﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Media;

namespace Forbidden_Island
{
    public partial class frm : Form
    {
        //global water level
        int currentWaterLevel;
        int cardsDrawnByFloodLevel = 0;
        int countDrawnCards = 0;
        //create new game
        Game newGame;

        bool gameOver = false;
        #region lists for tiles, adventure deck, tilepanels, placecard and adventure deck, discard piles, and player hand list
            List<Tile> gameTiles;
            List<AdventureDeck> gameAdvDeck;
            List<AdventureDeck> gameAdvDiscard = new List<AdventureDeck>();
            AdventureDeck tempCard = new AdventureDeck();
            //List<PlayerClass> currentplayers;
            List<TilePanel> tilePanelList = new List<TilePanel>();
            List<PlaceCard> placeCardDeck;
            List<PlaceCard> placeCardDiscard = new List<PlaceCard>();
            List<Label> playerOneHandList = new List<Label>();
            List<Label> playerTwoHandList = new List<Label>();
            List<Label> playerThreeHandList = new List<Label>();
            List<Label> playerFourHandList = new List<Label>();
            List<Label> playerHandList = new List<Label>();
        #endregion

        #region panels, used in creating tile panel list
            Panel backPanel;
            Panel forePanel;
            TilePanel tempTilePanel;
        #endregion

        #region instantiate soundplayer
            SoundPlayer player = new SoundPlayer();
            SoundPlayer backgroundPlayer = new SoundPlayer();
        #endregion

        #region playerStats and valid moves
            //track index of current player, 0 is player 1, 1 is player 2, etc.
            int currentPlayer = 0;

            //holds player remaining moves 
            int remainingMoves = -1;

            //array for temporarily storing indexes of valid moves
            int[] currentValidMoves = new int[4];

            //array for enginer valid shore up tiles
            int[] engineerShoreTiles = new int[5];
        #endregion

        #region declares various boolean variables that serve as modes - used during player turn
            bool moveMode = false;
            bool shoreUpMode = false;
            bool tradeMode = false;
            int tileTradeLocation = -1;
            bool handlersSet = false;
            bool mustDiscard = false;
            bool sandbagsMode = false;
            bool helicopterMode = false;
            bool nextPhaseMode = false;
            bool playersFound = false;
            bool specialMode = false;
            string specialPlayer = "";
            bool pilotSpecialUsed = false;
            bool drawPhaseCompleted = false;
        //bool to determine if navigator special action mode is active
        bool navMode = false;

        //bool used to determine if explorer's movemode is active
        bool explorerMoveMode = false;

        //bool used to determine if explorer's shoreupmode is active
        bool explorerShoreUpMode = false;
        #endregion

        #region booleans used for determining player trading with current player
            bool tradeWithEngineer = false;
            bool tradeWithNavigator = false;
            bool tradeWithPilot = false;
            bool tradeWithExplorer = false;
        #endregion

        #region engineer shored tile variables
            //tracks how many tiles engineer shores up with special action
            int shoredTiles = 0;

            //integer used for determing whether there are two shorable tiles adjacent to engineer
            int validShoreTiles;
            //used to flag whether clicked tile is valid
            bool engineerValidShoreUp = false;
        #endregion

        #region navigator special phase variables
            //determines whether player token has yet been clicked during navigator special phase
            bool playerTokenClicked = false;

            //int for index of player clicked during navigator phase
            int playerIndexClicked = -1;

            //bool to determine if navigator special first move has been made
            bool navFirstMove = false;

            //bool to determine if navigator special second move has been made
            bool navSecondMove = false;
        #endregion

        #region treasure variables
            //treasure claimed variables
            bool chaliceClaimed = false;
            bool statueClaimed = false;
            bool totemClaimed = false;
            bool carvingClaimed = false;
        #endregion

        #region set variables for helicopter lift
            bool liftPlayerOne = false;
            bool liftPlayerTwo = false;
            bool liftPlayerThree = false;
            bool liftPlayerFour = false;

            //stores whether first tile has been selected
            bool liftFirstTileSelected = false;
            //checks to make sure a tile with players on it has been selected
            bool liftPlayersFound = false;
            //stores whether lift was confirmed or cancelled;
            bool liftConfirmed = false;
            bool liftSecondTileSelected = false;
            //int to store lift tile that was selected
            int liftFirstTileLocation = -1;
            int liftSecondTileLocation = -1;
        #endregion

        #region explorer specific variables
            //variable to store explorer's valid moves
            int[] explorerValidMoves = new int[8];

            //array to hold valid moves during nav phase
            int[] navValidMoves = new int[4];
        #endregion

        #region adventure card variables
            //stores clicked adventure card index
            int adventureCardLabelLocation = -1;

            //tracks whether second adventure card has been drawn
            bool secondAdvCardDrawn = false;
            //stores player index of clicked adventure card
            int playerPlayingCard = -1;
        #endregion

        #region dummycard, thread sleep duration, tooltip
            //created dummy card for player hands when index is empty
            AdventureDeck dummyCard;

            //pause variable for thread.sleep
            int sleepDuration = 1000;
            int watersRiseDuration = 4000;

            //controls for tooltips
            ToolTip adventureCardTooltip;
        #endregion

        #region reset Turn variables
            List<Tile> tempGameTiles;
            List<AdventureDeck> tempGameAdvDeck;
            List<AdventureDeck> tempGameAdvDiscard = new List<AdventureDeck>();
            //List<PlayerClass> currentplayers;
            List<TilePanel> tempTilePanelList = new List<TilePanel>();
            List<PlaceCard> tempPlaceCardDeck;
            List<PlaceCard> tempPlaceCardDiscard = new List<PlaceCard>();
            List<Label> tempPlayerOneHandList = new List<Label>();
            List<Label> tempPlayerTwoHandList = new List<Label>();
            List<Label> tempPlayerThreeHandList = new List<Label>();
            List<Label> tempPlayerFourHandList = new List<Label>();
            List<Label> tempPlayerHandList = new List<Label>();
            Game tempNewGame = new Game();
            bool tempChaliceClaimed = false;
            bool tempStatueClaimed = false;
            bool tempTotemClaimed = false;
            bool tempCarvingClaimed = false;
            int tempCurrentWaterLevel = 0;
            string placeCardDiscardText;
            Color placeCardDiscardForeColor;
            Color placeCardDiscardBackColor;
            Color pbPlacesDiscardBackColor;
            string adventureDeckDiscardText;
            Color adventureDeckDiscardForeColor;
            Color adventureDeckDiscardBackColor;
            Color pbAdventureDeckDiscardBackColor;

        #endregion
            public frm()
        {
            InitializeComponent();
            //tooltips for adventure cards
            this.components = new System.ComponentModel.Container();
            this.adventureCardTooltip = new System.Windows.Forms.ToolTip(this.components);
        }

        //start new game menu click
        #region start new game click
        private void startNewGameToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            resetAllVariables();
            newGame = new Game();
            newGame.fillValidMoves();
            newGame.fillExplorerMoves();
            //start new game music
            backgroundPlayer.SoundLocation = Environment.CurrentDirectory + "\\ocean-waves-1.wav";
            backgroundPlayer.PlayLooping();

            //create objects: tiles, adventure deck, player list and place card deck
            gameTiles = newGame.getTileList;
            gameAdvDeck = newGame.createAdvDeck();
            newGame.createplayers();
            placeCardDeck = newGame.createPlaceCardDeck();
            placeCardDeck.ShuffleInPlace();
            gameAdvDeck.ShuffleInPlace();

            //populate GUI
            createAllTiles();
            fillAllTiles();

            //reset gui objects to new game settings
            clearAllPlayerMarkers();
            resetTreasures();
            clearWaterLevel();

            //temporary method for testing rich text box
            showSampleHistoryText();

            //set initial water level, then deal player hands
            setWaterLevel(1);

            DealInitialHand();
            updatePlayerHands();

            //add event handlers to all panels, labels and pictureboxes on board
            setHandlers();

            //do initial flood phase
            initialFloodPhase();

            //initialize player token start locations
            InitializePlayers();
            startNewGamePlayerReset();
            setDeckLabels();

        }
        #endregion
        //form load - sets initial game music and fills valid moves
        #region form load
        private void frm_Load(object sender, EventArgs e)
        {
            backgroundPlayer.SoundLocation = Environment.CurrentDirectory + "\\seashore.wav";
            BuildPlayerHandLabels();
            backgroundPlayer.PlayLooping();
            dummyCard = new AdventureDeck("DummyCard", "", false, false, false, false, 0, "", Color.Black, Color.Black);
        }
        #endregion
        //removes all player marker images from picture boxes
        #region clearPlayerMarkers
        public void clearAllPlayerMarkers()
        {
            //method to remove all player markers from the game board
            for (int i = 0; i <= 23; i++)
            {
                tilePanelList[i].forePanel.Controls[1].BackgroundImage = null;
                tilePanelList[i].forePanel.Controls[2].BackgroundImage = null;
                tilePanelList[i].forePanel.Controls[3].BackgroundImage = null;
                tilePanelList[i].forePanel.Controls[4].BackgroundImage = null;
            }
        }
        #endregion
        //creates all tiles
        #region createAllTiles
        private void createAllTiles()
        {
            rtbGameHistory.AppendText("Creating game board tiles...\n");
            rtbGameHistory.ScrollToCaret();
            //these variables will remain static, since they will be child controls and so their location is relative to the containing forepanel
            int labelLocX = 3;
            int labelLocY = 3;
            int redTokenX = 20;
            int redTokenY = 39;
            int yellowTokenX = 45;
            int yellowTokenY = 39;
            int blueTokenX = 20;
            int blueTokenY = 64;
            int greenTokenX = 45;
            int greenTokenY = 64;

            //these variables will be reset for every row so that the panels are drawn in the correct positions
            int backLocX = 404;
            int backLocY = 90;
            int foreLocX = 407;
            int foreLocY = 93;

            int count = 0;

            //loop to create first row
            for (int i = 0; i < 2; i++)
            {
                //create background panel
                backPanel = new Panel();
                backPanel.Location = new Point(backLocX, backLocY);
                backPanel.Size = new Size(100, 100);

                //create foreground panel
                forePanel = new Panel();
                forePanel.Location = new Point(foreLocX, foreLocY);
                forePanel.Size = new Size(94, 94);
                forePanel.ForeColor = Color.Green;
                forePanel.BackColor = Color.Yellow;
                forePanel.BackgroundImageLayout = ImageLayout.Stretch;

                //create tile panel (which contains backpanel and forepanel), add it to the tile list, then to the form, then bring both to front
                tempTilePanel = new TilePanel(forePanel, backPanel);
                tilePanelList.Add(tempTilePanel);
                //note that now that the tile panel has been added to the tilepanellist, the panel and it's properties 
                //can be referenced directly through the tilepanellist object - ex: tilePanelList[0].forePanel refers
                //directly to the first board location (both the background panel and foreground panel) and you can set 
                //properties which show up immediately on the windows form -- such as tilePanelList[0].forePanel.BackColor = Color.Orange
                //or tilePanelList[0].backPanel.BackColor = Color.Black
                this.Controls.Add(tilePanelList[i].backPanel);
                this.Controls.Add(tilePanelList[i].forePanel);
                tilePanelList[i].forePanel.BringToFront();

                //create label and add to foreground panel
                Label textLabel = new Label();
                textLabel.Location = new Point(labelLocX, labelLocY);
                textLabel.Size = new Size(86, 36);
                textLabel.Font = new Font("verdana", 9.75f);
                textLabel.Text = "Tarnished Gate";
                textLabel.TextAlign = ContentAlignment.MiddleCenter;
                textLabel.BackColor = Color.Transparent;
                forePanel.Controls.Add(textLabel);

                //create red token picturebox and add to foreground panel
                PictureBox redToken = new PictureBox();
                redToken.Location = new Point(redTokenX, redTokenY);
                redToken.Size = new Size(25, 25);
                redToken.BackgroundImageLayout = ImageLayout.Stretch;
                redToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\red token.png");
                redToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(redToken);

                //create yellow token picturebox and add to foreground panel
                PictureBox yellowToken = new PictureBox();
                yellowToken.Location = new Point(yellowTokenX, yellowTokenY);
                yellowToken.Size = new Size(25, 25);
                yellowToken.BackgroundImageLayout = ImageLayout.Stretch;
                yellowToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\yellow token.png");
                yellowToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(yellowToken);

                //create blue token picturebox and add to foreground panel
                PictureBox blueToken = new PictureBox();
                blueToken.Location = new Point(blueTokenX, blueTokenY);
                blueToken.Size = new Size(25, 25);
                blueToken.BackgroundImageLayout = ImageLayout.Stretch;
                blueToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\blue token.png");
                blueToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(blueToken);

                //create green token picturebox and add to foreground panel
                PictureBox greenToken = new PictureBox();
                greenToken.Location = new Point(greenTokenX, greenTokenY);
                greenToken.Size = new Size(25, 25);
                greenToken.BackgroundImageLayout = ImageLayout.Stretch;
                greenToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\green token.png");
                greenToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(greenToken);

                //iterate location and count variables
                backLocX += 102;
                foreLocX += 102;
                count++;
            }

            //set correct starting x and y locations
            backLocX = 302;
            backLocY = 192;
            foreLocX = 305;
            foreLocY = 195;
            //loop to create second row
            for (int j = 0; j <= 3; j++)
            {
                //create background panel
                backPanel = new Panel();
                backPanel.Location = new Point(backLocX, backLocY);
                backPanel.Size = new Size(100, 100);

                //create foreground panel
                forePanel = new Panel();
                forePanel.Location = new Point(foreLocX, foreLocY);
                forePanel.Size = new Size(94, 94);
                forePanel.ForeColor = Color.Green;
                forePanel.BackColor = Color.Yellow;
                forePanel.BackgroundImageLayout = ImageLayout.Stretch;

                //create tile panel (which contains backpanel and forepanel), add it to the tile list, then to the form, then bring both to front
                TilePanel tempTilePanel = new TilePanel(forePanel, backPanel);
                tilePanelList.Add(tempTilePanel);
                this.Controls.Add(tilePanelList[count].backPanel);
                this.Controls.Add(tilePanelList[count].forePanel);
                tilePanelList[count].forePanel.BringToFront();

                //create label and add to foreground panel
                Label textLabel = new Label();
                textLabel.Location = new Point(labelLocX, labelLocY);
                textLabel.Size = new Size(86, 36);
                textLabel.Font = new Font("verdana", 9.75f);
                textLabel.Text = "Tarnished Gate";
                textLabel.TextAlign = ContentAlignment.MiddleCenter;
                textLabel.BackColor = Color.Transparent;
                forePanel.Controls.Add(textLabel);

                //create red token picturebox and add to foreground panel
                PictureBox redToken = new PictureBox();
                redToken.Location = new Point(redTokenX, redTokenY);
                redToken.Size = new Size(25, 25);
                redToken.BackgroundImageLayout = ImageLayout.Stretch;
                redToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\red token.png");
                redToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(redToken);

                //create yellow token picturebox and add to foreground panel
                PictureBox yellowToken = new PictureBox();
                yellowToken.Location = new Point(yellowTokenX, yellowTokenY);
                yellowToken.Size = new Size(25, 25);
                yellowToken.BackgroundImageLayout = ImageLayout.Stretch;
                yellowToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\yellow token.png");
                yellowToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(yellowToken);

                //create blue token picturebox and add to foreground panel
                PictureBox blueToken = new PictureBox();
                blueToken.Location = new Point(blueTokenX, blueTokenY);
                blueToken.Size = new Size(25, 25);
                blueToken.BackgroundImageLayout = ImageLayout.Stretch;
                blueToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\blue token.png");
                blueToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(blueToken);

                //create green token picturebox and add to foreground panel
                PictureBox greenToken = new PictureBox();
                greenToken.Location = new Point(greenTokenX, greenTokenY);
                greenToken.Size = new Size(25, 25);
                greenToken.BackgroundImageLayout = ImageLayout.Stretch;
                greenToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\green token.png");
                greenToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(greenToken);

                backLocX += 102;
                foreLocX += 102;
                count++;
            }

            //set correct starting x and y locations
            backLocX = 200;
            backLocY = 294;
            foreLocX = 203;
            foreLocY = 297;
            //loop to create third row
            for (int j = 0; j <= 5; j++)
            {
                //create background panel
                backPanel = new Panel();
                backPanel.Location = new Point(backLocX, backLocY);
                backPanel.Size = new Size(100, 100);

                //create foreground panel
                forePanel = new Panel();
                forePanel.Location = new Point(foreLocX, foreLocY);
                forePanel.Size = new Size(94, 94);
                forePanel.ForeColor = Color.Green;
                forePanel.BackColor = Color.Yellow;
                forePanel.BackgroundImageLayout = ImageLayout.Stretch;

                //create tile panel (which contains backpanel and forepanel), add it to the tile list, then to the form, then bring both to front
                TilePanel tempTilePanel = new TilePanel(forePanel, backPanel);
                tilePanelList.Add(tempTilePanel);
                this.Controls.Add(tilePanelList[count].backPanel);
                this.Controls.Add(tilePanelList[count].forePanel);
                tilePanelList[count].forePanel.BringToFront();

                //create label and add to foreground panel
                Label textLabel = new Label();
                textLabel.Location = new Point(labelLocX, labelLocY);
                textLabel.Size = new Size(86, 36);
                textLabel.Font = new Font("verdana", 9.75f);
                textLabel.Text = "Tarnished Gate";
                textLabel.TextAlign = ContentAlignment.MiddleCenter;
                textLabel.BackColor = Color.Transparent;
                forePanel.Controls.Add(textLabel);

                //create red token picturebox and add to foreground panel
                PictureBox redToken = new PictureBox();
                redToken.Location = new Point(redTokenX, redTokenY);
                redToken.Size = new Size(25, 25);
                redToken.BackgroundImageLayout = ImageLayout.Stretch;
                redToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\red token.png");
                redToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(redToken);

                //create yellow token picturebox and add to foreground panel
                PictureBox yellowToken = new PictureBox();
                yellowToken.Location = new Point(yellowTokenX, yellowTokenY);
                yellowToken.Size = new Size(25, 25);
                yellowToken.BackgroundImageLayout = ImageLayout.Stretch;
                yellowToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\yellow token.png");
                yellowToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(yellowToken);

                //create blue token picturebox and add to foreground panel
                PictureBox blueToken = new PictureBox();
                blueToken.Location = new Point(blueTokenX, blueTokenY);
                blueToken.Size = new Size(25, 25);
                blueToken.BackgroundImageLayout = ImageLayout.Stretch;
                blueToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\blue token.png");
                blueToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(blueToken);

                //create green token picturebox and add to foreground panel
                PictureBox greenToken = new PictureBox();
                greenToken.Location = new Point(greenTokenX, greenTokenY);
                greenToken.Size = new Size(25, 25);
                greenToken.BackgroundImageLayout = ImageLayout.Stretch;
                greenToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\green token.png");
                greenToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(greenToken);

                backLocX += 102;
                foreLocX += 102;
                count++;
            }
            //set correct starting x and y locations
            backLocX = 200;
            backLocY = 396;
            foreLocX = 203;
            foreLocY = 399;
            //loop to create fourth row
            for (int j = 0; j <= 5; j++)
            {
                //create background panel
                backPanel = new Panel();
                backPanel.Location = new Point(backLocX, backLocY);
                backPanel.Size = new Size(100, 100);

                //create foreground panel
                forePanel = new Panel();
                forePanel.Location = new Point(foreLocX, foreLocY);
                forePanel.Size = new Size(94, 94);
                forePanel.ForeColor = Color.Green;
                forePanel.BackColor = Color.Yellow;
                forePanel.BackgroundImageLayout = ImageLayout.Stretch;

                //create tile panel (which contains backpanel and forepanel), add it to the tile list, then to the form, then bring both to front
                TilePanel tempTilePanel = new TilePanel(forePanel, backPanel);
                tilePanelList.Add(tempTilePanel);
                this.Controls.Add(tilePanelList[count].backPanel);
                this.Controls.Add(tilePanelList[count].forePanel);
                tilePanelList[count].forePanel.BringToFront();

                //create label and add to foreground panel
                Label textLabel = new Label();
                textLabel.Location = new Point(labelLocX, labelLocY);
                textLabel.Size = new Size(86, 36);
                textLabel.Font = new Font("verdana", 9.75f);
                textLabel.Text = "Tarnished Gate";
                textLabel.TextAlign = ContentAlignment.MiddleCenter;
                textLabel.BackColor = Color.Transparent;
                forePanel.Controls.Add(textLabel);

                //create red token picturebox and add to foreground panel
                PictureBox redToken = new PictureBox();
                redToken.Location = new Point(redTokenX, redTokenY);
                redToken.Size = new Size(25, 25);
                redToken.BackgroundImageLayout = ImageLayout.Stretch;
                redToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\red token.png");
                redToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(redToken);

                //create yellow token picturebox and add to foreground panel
                PictureBox yellowToken = new PictureBox();
                yellowToken.Location = new Point(yellowTokenX, yellowTokenY);
                yellowToken.Size = new Size(25, 25);
                yellowToken.BackgroundImageLayout = ImageLayout.Stretch;
                yellowToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\yellow token.png");
                yellowToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(yellowToken);

                //create blue token picturebox and add to foreground panel
                PictureBox blueToken = new PictureBox();
                blueToken.Location = new Point(blueTokenX, blueTokenY);
                blueToken.Size = new Size(25, 25);
                blueToken.BackgroundImageLayout = ImageLayout.Stretch;
                blueToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\blue token.png");
                blueToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(blueToken);

                //create green token picturebox and add to foreground panel
                PictureBox greenToken = new PictureBox();
                greenToken.Location = new Point(greenTokenX, greenTokenY);
                greenToken.Size = new Size(25, 25);
                greenToken.BackgroundImageLayout = ImageLayout.Stretch;
                greenToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\green token.png");
                greenToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(greenToken);

                backLocX += 102;
                foreLocX += 102;
                count++;
            }

            //set correct starting x and y locations
            backLocX = 302;
            backLocY = 498;
            foreLocX = 305;
            foreLocY = 501;
            //loop to create fifth row
            for (int j = 0; j <= 3; j++)
            {
                //create background panel
                backPanel = new Panel();
                backPanel.Location = new Point(backLocX, backLocY);
                backPanel.Size = new Size(100, 100);

                //create foreground panel
                forePanel = new Panel();
                forePanel.Location = new Point(foreLocX, foreLocY);
                forePanel.Size = new Size(94, 94);
                forePanel.ForeColor = Color.Green;
                forePanel.BackColor = Color.Yellow;
                forePanel.BackgroundImageLayout = ImageLayout.Stretch;

                //create tile panel (which contains backpanel and forepanel), add it to the tile list, then to the form, then bring both to front
                TilePanel tempTilePanel = new TilePanel(forePanel, backPanel);
                tilePanelList.Add(tempTilePanel);
                this.Controls.Add(tilePanelList[count].backPanel);
                this.Controls.Add(tilePanelList[count].forePanel);
                tilePanelList[count].forePanel.BringToFront();

                //create label and add to foreground panel
                Label textLabel = new Label();
                textLabel.Location = new Point(labelLocX, labelLocY);
                textLabel.Size = new Size(86, 36);
                textLabel.Font = new Font("verdana", 9.75f);
                textLabel.Text = "Tarnished Gate";
                textLabel.TextAlign = ContentAlignment.MiddleCenter;
                textLabel.BackColor = Color.Transparent;
                forePanel.Controls.Add(textLabel);

                //create red token picturebox and add to foreground panel
                PictureBox redToken = new PictureBox();
                redToken.Location = new Point(redTokenX, redTokenY);
                redToken.Size = new Size(25, 25);
                redToken.BackgroundImageLayout = ImageLayout.Stretch;
                redToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\red token.png");
                redToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(redToken);

                //create yellow token picturebox and add to foreground panel
                PictureBox yellowToken = new PictureBox();
                yellowToken.Location = new Point(yellowTokenX, yellowTokenY);
                yellowToken.Size = new Size(25, 25);
                yellowToken.BackgroundImageLayout = ImageLayout.Stretch;
                yellowToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\yellow token.png");
                yellowToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(yellowToken);

                //create blue token picturebox and add to foreground panel
                PictureBox blueToken = new PictureBox();
                blueToken.Location = new Point(blueTokenX, blueTokenY);
                blueToken.Size = new Size(25, 25);
                blueToken.BackgroundImageLayout = ImageLayout.Stretch;
                blueToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\blue token.png");
                blueToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(blueToken);

                //create green token picturebox and add to foreground panel
                PictureBox greenToken = new PictureBox();
                greenToken.Location = new Point(greenTokenX, greenTokenY);
                greenToken.Size = new Size(25, 25);
                greenToken.BackgroundImageLayout = ImageLayout.Stretch;
                greenToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\green token.png");
                greenToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(greenToken);

                backLocX += 102;
                foreLocX += 102;
                count++;
            }

            //set correct starting x and y locations
            backLocX = 404;
            backLocY = 600;
            foreLocX = 407;
            foreLocY = 603;
            //loop to create sixth row
            for (int j = 0; j <= 1; j++)
            {
                //create background panel
                backPanel = new Panel();
                backPanel.Location = new Point(backLocX, backLocY);
                backPanel.Size = new Size(100, 100);

                //create foreground panel
                forePanel = new Panel();
                forePanel.Location = new Point(foreLocX, foreLocY);
                forePanel.Size = new Size(94, 94);
                forePanel.ForeColor = Color.Green;
                forePanel.BackColor = Color.Yellow;
                forePanel.BackgroundImageLayout = ImageLayout.Stretch;

                //create tile panel (which contains backpanel and forepanel), add it to the tile list, then to the form, then bring both to front
                TilePanel tempTilePanel = new TilePanel(forePanel, backPanel);
                tilePanelList.Add(tempTilePanel);
                this.Controls.Add(tilePanelList[count].backPanel);
                this.Controls.Add(tilePanelList[count].forePanel);
                tilePanelList[count].forePanel.BringToFront();

                //create label and add to foreground panel
                Label textLabel = new Label();
                textLabel.Location = new Point(labelLocX, labelLocY);
                textLabel.Size = new Size(86, 36);
                textLabel.Font = new Font("verdana", 9.75f);
                textLabel.Text = "Tarnished Gate";
                textLabel.TextAlign = ContentAlignment.MiddleCenter;
                textLabel.BackColor = Color.Transparent;
                forePanel.Controls.Add(textLabel);

                //create red token picturebox and add to foreground panel
                PictureBox redToken = new PictureBox();
                redToken.Location = new Point(redTokenX, redTokenY);
                redToken.Size = new Size(25, 25);
                redToken.BackgroundImageLayout = ImageLayout.Stretch;
                redToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\red token.png");
                redToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(redToken);

                //create yellow token picturebox and add to foreground panel
                PictureBox yellowToken = new PictureBox();
                yellowToken.Location = new Point(yellowTokenX, yellowTokenY);
                yellowToken.Size = new Size(25, 25);
                yellowToken.BackgroundImageLayout = ImageLayout.Stretch;
                yellowToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\yellow token.png");
                yellowToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(yellowToken);

                //create blue token picturebox and add to foreground panel
                PictureBox blueToken = new PictureBox();
                blueToken.Location = new Point(blueTokenX, blueTokenY);
                blueToken.Size = new Size(25, 25);
                blueToken.BackgroundImageLayout = ImageLayout.Stretch;
                blueToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\blue token.png");
                blueToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(blueToken);

                //create green token picturebox and add to foreground panel
                PictureBox greenToken = new PictureBox();
                greenToken.Location = new Point(greenTokenX, greenTokenY);
                greenToken.Size = new Size(25, 25);
                greenToken.BackgroundImageLayout = ImageLayout.Stretch;
                greenToken.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\green token.png");
                greenToken.BackColor = Color.Transparent;
                forePanel.Controls.Add(greenToken);

                backLocX += 102;
                foreLocX += 102;
                count++;
            }
        }
        #endregion
        //populates all tiles
        #region fillAllTiles
        public void fillAllTiles()
        {
            rtbGameHistory.AppendText("Populating game board...\n");
            rtbGameHistory.ScrollToCaret();
            //iterates through the already shuffled list of tiles and the tilePanelList and adds them to the panels on the board
            //one at a time
            for (int i=0; i<=23; i++)
            {
                if(gameTiles[i].spec)
                    tilePanelList[i].forePanel.Controls[0].Font = new Font(tilePanelList[i].forePanel.Controls[0].Font, FontStyle.Bold);
                else
                    tilePanelList[i].forePanel.Controls[0].Font = new Font(tilePanelList[i].forePanel.Controls[0].Font, FontStyle.Regular);
                tilePanelList[i].forePanel.Controls[0].Text = gameTiles[i].Name;
                tilePanelList[i].forePanel.Controls[0].ForeColor = gameTiles[i].texColor;
                tilePanelList[i].forePanel.BackColor = gameTiles[i].tColor;
                tilePanelList[i].backPanel.BackColor = gameTiles[i].bColor;
                tilePanelList[i].backPanel.Visible = true;
                tilePanelList[i].forePanel.Visible = true;
                if (gameTiles[i].wStatus != "Flooded")
                    tilePanelList[i].forePanel.BackgroundImage = null;
                else if (gameTiles[i].wStatus == "Sunk")
                {
                    tilePanelList[i].forePanel.Visible = false;
                    tilePanelList[i].backPanel.Visible = false;
                }
                else if (gameTiles[i].wStatus == "Flooded")
                {
                    tilePanelList[i].forePanel.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\waterdrop3.png");
                    tilePanelList[i].forePanel.BackColor = Color.Turquoise;
                }
            }
        }
        #endregion
        //temporary method to test richtext box
        #region sample history text
        public void showSampleHistoryText()
        {
            //rtbGameHistory.AppendText("List of Players\n");
            //for (int i = 0; i < 4; ++i)
            //{
            //    rtbGameHistory.AppendText(currentplayers[i].PlayerName.ToString()+"\n");
            //    rtbGameHistory.AppendText(currentplayers[i].PlayerColor.ToString() + "\n");
            //}
            //rtbGameHistory.ScrollToCaret();
        }
        #endregion

        //clears all claimed treasure and initializes unclaimed treasures images
        #region reset treasures
        private void resetTreasures()
        {
            rtbGameHistory.AppendText("Resetting Treasures...\n");
            rtbGameHistory.ScrollToCaret();
            statueClaimed = false;
            carvingClaimed = false;
            totemClaimed = false;
            chaliceClaimed = false;
            pbUnclaimedChalice.Visible = true; // = Image.FromFile(Environment.CurrentDirectory + "\\chalice_top.png");
            pbUnclaimedStatue.Visible = true; // BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\statuette.png");
            pbUnclaimedDragon.Visible = true; // BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\fiery dragon.png");
            pbUnclaimedSphinx.Visible = true; // BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\airstatue.png");
            lblUnclaimedChalice.Visible = true;
            lblUnclaimedStatue.Visible = true;
            lblUnclaimedDragon.Visible = true;
            lblUnclaimedSphinx.Visible = true;
            pbClaimedChalice.Visible = false; // BackgroundImage = null;
            pbClaimedStatue.Visible = false; // BackgroundImage = null;
            pbClaimedDragon.Visible = false; // BackgroundImage = null;
            pbClaimedSphinx.Visible = false; // BackgroundImage = null;
            lblClaimedChalice.Visible = false;
            lblClaimedDragon.Visible = false;
            lblClaimedStatue.Visible = false;
            lblClaimedSphinx.Visible = false;
        }
        #endregion
        //resets water level and clears all images
        #region clears water level
        private void clearWaterLevel()
        {
            currentWaterLevel = 0;
            pbWLevel1.BackgroundImage = null;
            pbWLevel2.BackgroundImage = null;
            pbWLevel3.BackgroundImage = null;
            pbWLevel4.BackgroundImage = null;
            pbWLevel5.BackgroundImage = null;
            pbWLevel6.BackgroundImage = null;
            pbWLevel7.BackgroundImage = null;
            pbWLevel8.BackgroundImage = null;
            pbWLevel9.BackgroundImage = null;
            pbWLevel10.BackgroundImage = null;

        }
        #endregion
        //adjusts water level and sets appropriate images on based on height
        #region set water level
        private void setWaterLevel(int height)
        {
            for (int i = 1; i <= height; i++)
            {
                if (i == 1)
                {
                    pbWLevel1.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\wave.png");
                    cardsDrawnByFloodLevel = 2;
                }
                if (i == 2)
                {
                    pbWLevel2.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\wave.png");
                    cardsDrawnByFloodLevel = 2;
                }
                if (i == 3)
                {
                    pbWLevel3.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\wave.png");
                    cardsDrawnByFloodLevel = 3;
                }
                if (i == 4)
                {
                    pbWLevel4.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\wave.png");
                    cardsDrawnByFloodLevel = 3;
                }
                if (i == 5)
                {
                    pbWLevel5.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\wave.png");
                    cardsDrawnByFloodLevel = 3;
                }
                if (i == 6)
                {
                    pbWLevel6.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\wave.png");
                    cardsDrawnByFloodLevel = 4;
                }
                if (i == 7)
                {
                    pbWLevel7.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\wave.png");
                    cardsDrawnByFloodLevel = 4;
                }
                if (i == 8)
                {
                    pbWLevel8.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\wave.png");
                    cardsDrawnByFloodLevel = 5;
                }
                if (i == 9)
                {
                    pbWLevel9.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\wave.png");
                    cardsDrawnByFloodLevel = 5;
                }
                if (i == 10)
                    pbWLevel10.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\skull_xbones.png");
            }
            currentWaterLevel = height;
        }
        #endregion
        //returns index location of place tile given it's name
        #region find place tile
        private int findPlaceTile(string placeName)
        {
            for (int i = 0; i <= 23; i++)
            {
                if (gameTiles[i].Name == placeName)
                    return i;
            }
            return -1;
        }
        #endregion
        //draws card from flood deck based on current water level
        #region flood phase
        //this method is only fired at the game start - 6 tiles are flooded, per the pen and paper game rules
        private void initialFloodPhase()
        {
            rtbGameHistory.AppendText("Performing initial flood phase...\n");
            rtbGameHistory.ScrollToCaret();
            for (int i = 1; i <= 6; i++)
            {
                //draw top card
                PlaceCard tempPlaceCard = new PlaceCard();
                tempPlaceCard = placeCardDeck[0];
                //find tile of drawn place card
                int floodCardLocation = findPlaceTile(tempPlaceCard.Name);
                if (gameTiles[floodCardLocation].wStatus == "Dry")
                {
                    rtbGameHistory.AppendText(gameTiles[floodCardLocation].Name + " comes into play flooded!\n");
                    rtbGameHistory.ScrollToCaret();
                    if (gameTiles[floodCardLocation].spec)
                    {
                        tilePanelList[floodCardLocation].forePanel.BackColor = Color.Turquoise;
                        tilePanelList[floodCardLocation].forePanel.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\waterdrop3.png");
                    }
                    else
                    {
                        tilePanelList[floodCardLocation].backPanel.Visible = false;
                        tilePanelList[floodCardLocation].forePanel.BackColor = Color.Turquoise;
                        tilePanelList[floodCardLocation].forePanel.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\waterdrop3.png");
                    }
                    gameTiles[floodCardLocation].wStatus = "Flooded";
                    //set discard pile properties to match drawn card
                    lblPlaceCardDiscardName.Text = tempPlaceCard.Name;
                    if (tempPlaceCard.SpecialCard)
                        lblPlaceCardDiscardName.Font = new Font(lblPlaceCardDiscardName.Font, FontStyle.Bold);
                    else
                        lblPlaceCardDiscardName.Font = new Font(lblPlaceCardDiscardName.Font, FontStyle.Regular);
                    lblPlaceCardDiscardName.BackColor = tempPlaceCard.LblBackColor;
                    lblPlaceCardDiscardName.ForeColor = tempPlaceCard.LblTextColor;
                    pbPlacesDiscard.BackColor = tempPlaceCard.CardBackColor;
                    placeCardDiscard.Add(tempPlaceCard);
                    placeCardDeck.RemoveAt(0);
                }
            }
            lblPlacesDeckCount.Text = placeCardDeck.Count().ToString();
            lblPlacesDiscardCount.Text = placeCardDiscard.Count().ToString();
            lblAdventureDeckCount.Text = gameAdvDeck.Count().ToString();
            lblAdventureDeckDiscardCount.Text = gameAdvDiscard.Count().ToString();
        }
        private void doFloodPhase()
        {
            int sleepDuration = 1500;
            Random randomMove = new Random();
            int playerMove = -1;
            bool sunkMovesAvailable = false;
            int validMovesCount = 0;

            lblBannerText.Text = "Flood Phase! Drawing " + cardsDrawnByFloodLevel + " cards this turn.";
            rtbGameHistory.AppendText("++++Start of Flood Phase! Drawing " + cardsDrawnByFloodLevel + " cards this turn++++\n");
            rtbGameHistory.ScrollToCaret();
            player.SoundLocation = Environment.CurrentDirectory + "\\shipbell.wav";
            player.Play();
            System.Threading.Thread.Sleep(sleepDuration);
            for (int i = 1; i <= cardsDrawnByFloodLevel; i++)
            {
                if (!gameOver)
                {
                    //draw top card
                    PlaceCard tempPlaceCard = new PlaceCard();
                    tempPlaceCard = placeCardDeck[0];
                    //rtbGameHistory.AppendText("Drawing top card from places deck...\n");
                    player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                    player.Play();
                    System.Threading.Thread.Sleep(sleepDuration - 300);
                    //find tile of drawn place card
                    int floodCardLocation = findPlaceTile(tempPlaceCard.Name);
                    if (gameTiles[floodCardLocation].wStatus == "Flooded")
                    {
                        lblBannerText.Text = gameTiles[floodCardLocation].Name + " was drawn, and sinks!\n";
                        rtbGameHistory.AppendText(gameTiles[floodCardLocation].Name + " was drawn, and sinks!\n");
                        rtbGameHistory.ScrollToCaret();
                        player.SoundLocation = Environment.CurrentDirectory + "\\scary.wav";
                        player.Play();
                        System.Threading.Thread.Sleep(sleepDuration - 300);
                        gameTiles[floodCardLocation].wStatus = "Sunk";
                        tilePanelList[floodCardLocation].backPanel.Visible = false;
                        tilePanelList[floodCardLocation].forePanel.Visible = false;
                        placeCardDeck.RemoveAt(0);
                        //determine whether players are on the sunk tile, and have them swim to safety if it's possible to do so
                        for (int m = 0; m <= 3; m++)
                        {
                            if (newGame.ValidMoves[floodCardLocation, m] != -1)
                            {
                                if (gameTiles[newGame.ValidMoves[floodCardLocation, m]].wStatus != "Sunk")
                                {
                                    currentValidMoves[m] = newGame.ValidMoves[floodCardLocation, m];
                                }
                                else
                                    currentValidMoves[m] = -1;
                            }
                        }
                        //check for player drowning / game lost
                        for (int q = 0; q <= currentValidMoves.Count() - 1; q++)
                        {
                            if (currentValidMoves[q] != -1)
                                sunkMovesAvailable = true;
                        }
                        for (int n = 0; n <= 3; n++)
                        {
                            if (newGame.playersList[n].CurrentLocation == floodCardLocation)
                            {
                                if (!sunkMovesAvailable)
                                {
                                    lblBannerText.Text = newGame.playersList[n].PlayerName + " is lost at sea, and drowns!  GAME OVER!";
                                    rtbGameHistory.AppendText(newGame.playersList[n].PlayerName + " is lost at sea, and drowns!  GAME OVER!");
                                    rtbGameHistory.ScrollToCaret();
                                    doGameOver();
                                }
                                else
                                {
                                    Array.Sort(currentValidMoves);
                                    Array.Reverse(currentValidMoves);
                                    for (int z = 0; z < currentValidMoves.Count(); z++)
                                    {
                                        if (currentValidMoves[z] != -1)
                                            validMovesCount++;
                                    }
                                    playerMove = (int)randomMove.Next(0, validMovesCount);
                                    tilePanelList[newGame.playersList[n].CurrentLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                                    tilePanelList[currentValidMoves[playerMove]].forePanel.Controls[n + 1].BackgroundImage =
                                        newGame.playersList[n].PlayerToken;
                                    newGame.playersList[n].CurrentLocation = currentValidMoves[playerMove];
                                    lblBannerText.Text = newGame.playersList[n].PlayerName + " becomes stranded at sea!  He swims desperately to " +
                                        gameTiles[currentValidMoves[playerMove]].Name + "!\n";
                                    rtbGameHistory.AppendText(newGame.playersList[n].PlayerName + " becomes stranded at sea!  He swims desperately to " +
                                        gameTiles[currentValidMoves[playerMove]].Name + "!\n");
                                    rtbGameHistory.ScrollToCaret();
                                }
                            }
                        }
                    }
                    //flood selected tile if it's currently dry
                    if (gameTiles[floodCardLocation].wStatus == "Dry")
                    {
                        lblBannerText.Text = gameTiles[floodCardLocation].Name + " was drawn, and becomes flooded!\n";
                        rtbGameHistory.AppendText(gameTiles[floodCardLocation].Name + " was drawn, and becomes flooded!\n");
                        rtbGameHistory.ScrollToCaret();
                        player.SoundLocation = Environment.CurrentDirectory + "\\Bubbling.wav";
                        player.Play();
                        System.Threading.Thread.Sleep(sleepDuration - 300);
                        if (gameTiles[floodCardLocation].spec)
                        {
                            tilePanelList[floodCardLocation].forePanel.BackColor = Color.Turquoise;
                            tilePanelList[floodCardLocation].forePanel.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\waterdrop3.png");
                        }
                        else
                        {
                            tilePanelList[floodCardLocation].backPanel.Visible = false;
                            tilePanelList[floodCardLocation].forePanel.BackColor = Color.Turquoise;
                            tilePanelList[floodCardLocation].forePanel.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\waterdrop3.png");
                        }
                        gameTiles[floodCardLocation].wStatus = "Flooded";
                        //set discard pile properties to match drawn card
                        lblPlaceCardDiscardName.Text = tempPlaceCard.Name;
                        if (tempPlaceCard.SpecialCard)
                            lblPlaceCardDiscardName.Font = new Font(lblPlaceCardDiscardName.Font, FontStyle.Bold);
                        else
                            lblPlaceCardDiscardName.Font = new Font(lblPlaceCardDiscardName.Font, FontStyle.Regular);
                        lblPlaceCardDiscardName.BackColor = tempPlaceCard.LblBackColor;
                        lblPlaceCardDiscardName.ForeColor = tempPlaceCard.LblTextColor;
                        pbPlacesDiscard.BackColor = tempPlaceCard.CardBackColor;
                        placeCardDiscard.Add(tempPlaceCard);
                        placeCardDeck.RemoveAt(0);
                    }
                    if (placeCardDeck.Count == 0)
                    {
                        shufflePlaceDiscardIntoPlaces();
                    }
                }
                System.Threading.Thread.Sleep(sleepDuration);
                nextPhaseMode = false;
                checkWinLoss();
                setDeckLabels();
            }
            if (!gameOver)
            {
                rtbGameHistory.AppendText("++++End of Flood Phase!++++\n");
                rtbGameHistory.ScrollToCaret();
                backgroundPlayer.PlayLooping();
            }
        }
        #endregion
        //method to shuffle discard pile and place on top of places deck
        #region shuffle discard into places
        public void shufflePlaceDiscardIntoPlaces()
        {
            placeCardDiscard.ShuffleInPlace();
            int countDiscardPile = placeCardDiscard.Count - 1;
            if (placeCardDeck.Count == 0)
            {
                rtbGameHistory.AppendText("Places draw deck empty - shuffling discard into places deck.\n");
                rtbGameHistory.ScrollToCaret();
                for (int i = 0; i <= countDiscardPile; i++)
                {
                    placeCardDeck.Insert(0, placeCardDiscard[i]);
                }
                for (int i = 0; i <= countDiscardPile; i++)
                {
                    placeCardDiscard.RemoveAt(0);
                }
            }
            else
            {
                rtbGameHistory.AppendText("-->Shuffling places discard pile and placing on top of places deck!\n");
                rtbGameHistory.ScrollToCaret();
                for (int i = 0; i <= countDiscardPile; i++)
                {
                    placeCardDeck.Insert(0, placeCardDiscard[i]);
                }
                for (int i = 0; i <= countDiscardPile; i++)
                {
                    placeCardDiscard.RemoveAt(0);
                }
            }
            lblPlaceCardDiscardName.Text = "(Empty)";
            lblPlaceCardDiscardName.ForeColor = Color.White;
            lblPlaceCardDiscardName.BackColor = Color.Black;
            pbPlacesDiscard.BackColor = Color.Black;
            player.SoundLocation = Environment.CurrentDirectory + "\\shuffle.wav";
            player.Play();
            System.Threading.Thread.Sleep(800);
        }
        #endregion
        //test places draw deck
        #region test places deck
        private void btnTestPlaces_Click(object sender, EventArgs e)
        {
            doFloodPhase();
            backgroundPlayer.PlayLooping();
        }
        #endregion
        //button click test waters rise
        private void btnTestWatersRise_Click(object sender, EventArgs e)
        {
            shufflePlaceDiscardIntoPlaces();
        }
        //sets player token starting locations
        private void InitializePlayers()
        {
            //initialize engineer start
            string startTileName = "Skull Rock";
            int tileLocation = findPlaceTile(startTileName);
            tilePanelList[tileLocation].forePanel.Controls[1].BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\red token.png");
            newGame.playersList[0].CurrentLocation = tileLocation;
            //initialize navigator start
            startTileName = "Tarnished Gate";
            tileLocation = findPlaceTile(startTileName);
            tilePanelList[tileLocation].forePanel.Controls[2].BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\yellow token.png");
            newGame.playersList[1].CurrentLocation = tileLocation;
            //initialize pilot start
            startTileName = "Freedom's Landing";
            tileLocation = findPlaceTile(startTileName);
            tilePanelList[tileLocation].forePanel.Controls[3].BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\blue token.png");
            newGame.playersList[2].CurrentLocation = tileLocation;
            //initialize explorer start
            startTileName = "Widow's Peak";
            tileLocation = findPlaceTile(startTileName);
            tilePanelList[tileLocation].forePanel.Controls[4].BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\green token.png");
            newGame.playersList[3].CurrentLocation = tileLocation;
            currentPlayer = 0;
            remainingMoves = 3;
            lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " goes first!\n";
            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " goes first!\n");
            btnActionSubmit.Enabled = true;
            btnCancel.Enabled = true;
            lblSpecialDisplay.Text = newGame.playersList[currentPlayer].ActionText;
            lblSpecialDisplay.ForeColor = newGame.playersList[currentPlayer].PlayerColor;
            rtbGameHistory.ScrollToCaret();
            gbTurn.Text = newGame.playersList[currentPlayer].PlayerName + "'s Available Actions";
            lblSpecialDisplay.Text = newGame.playersList[currentPlayer].ActionText;
            lblSpecialDisplay.ForeColor = newGame.playersList[currentPlayer].PlayerColor;
            lblActionsRemaining.Text = remainingMoves.ToString();
            saveGameState();
            checkResetTurn();
        }
        //creates player hand labels
        #region build player hand labels
        private void BuildPlayerHandLabels()
        {
            int x = 207;
            int y = 853;
            for (int i = 0; i <= 23; ++i)
            {
                Label playerhand = new Label();
                playerhand.Location = new Point(x, y);
                playerhand.Size = new Size(136, 14);
                //this.Controls.Add(playerhand);
                playerhand.BringToFront();
                playerhand.Font = new Font("Verdana", 8);
                playerhand.Font = new Font(playerhand.Font, FontStyle.Bold);
                playerhand.BackColor = Color.Khaki;
                playerhand.ForeColor = Color.Red;
                playerhand.TextAlign = ContentAlignment.MiddleCenter;
                playerhand.BorderStyle = BorderStyle.FixedSingle;
                playerhand.Visible = false;
                playerHandList.Add(playerhand);
                if (i <= 5)
                {
                    playerOneHandList.Add(playerhand);
                    this.Controls.Add(playerhand);
                }
                else if (i <= 11)
                {
                    playerTwoHandList.Add(playerhand);
                    this.Controls.Add(playerhand);
                }
                else if (i <= 17)
                {
                    playerThreeHandList.Add(playerhand);
                    this.Controls.Add(playerhand);
                }
                else
                {
                    playerFourHandList.Add(playerhand);
                    this.Controls.Add(playerhand);
                }
                y = y + 17;
                if (y == 955)
                {
                    x = x + 152;
                    y = 853;  
                }  
            }
        }
        private void updatePlayerHands()
        {
            int firstDummy = -1;
            bool firstDummyFound = false;
            int indexSwitchCard = -1;
            bool indexSet = false;
            //iterate through all player hands, find first dummy card and switch the next-to-last index with the dummy card in current position
            //this assures that playable active card hands are always the lowest numbers in the list
            for (int i = 0; i <= 3; i++)
            {
                firstDummyFound = false;
                indexSet = false;
                for (int j = 0; j <= 5; j++)
                {
                    if (newGame.playersList[i].PlayerCardHand[j].Cardname == "DummyCard")
                        if (!firstDummyFound)
                        {
                            firstDummy = j;
                            firstDummyFound = true;
                        }
                }
                if (firstDummy !=5 && firstDummyFound)
                {
                    for (int j = firstDummy+1; j <= 5; j++)
                    {
                        if (newGame.playersList[i].PlayerCardHand[j].Cardname == "DummyCard")
                        {
                            if (!indexSet)
                            {
                                indexSwitchCard = j - 1;
                                indexSet = true;
                            }
                        }
                        else if (j == 5 && !indexSet)
                        {
                            indexSwitchCard = j;
                            indexSet = true;
                        }
                    }
                    if (indexSwitchCard == -1)
                        indexSwitchCard = 5;
                    if (indexSwitchCard != firstDummy)
                    {
                        newGame.playersList[i].PlayerCardHand[firstDummy] = newGame.playersList[i].PlayerCardHand[indexSwitchCard];
                        newGame.playersList[i].PlayerCardHand[indexSwitchCard] = dummyCard;
                    }
                }
            }
            for (int i = 0; i < newGame.playersList[0].PlayerCardHand.Count(); i++)
            {
                if (newGame.playersList[0].PlayerCardHand[i].Cardname == "DummyCard")
                {
                    playerOneHandList[i].Enabled = false;
                    playerOneHandList[i].Visible = false;
                }
                else
                {
                    playerOneHandList[i].Text = newGame.playersList[0].PlayerCardHand[i].Cardname;
                    playerOneHandList[i].BackColor = newGame.playersList[0].PlayerCardHand[i].CardBackground;
                    playerOneHandList[i].ForeColor = newGame.playersList[0].PlayerCardHand[i].CardForecolor;
                    playerOneHandList[i].Enabled = true;
                    playerOneHandList[i].Visible = true;
                }
            }
            for (int i = 0; i < newGame.playersList[1].PlayerCardHand.Count(); i++)
            {
                if (newGame.playersList[1].PlayerCardHand[i].Cardname == "DummyCard")
                {
                    playerTwoHandList[i].Enabled = false;
                    playerTwoHandList[i].Visible = false;
                }
                else
                {
                    playerTwoHandList[i].Text = newGame.playersList[1].PlayerCardHand[i].Cardname;
                    playerTwoHandList[i].BackColor = newGame.playersList[1].PlayerCardHand[i].CardBackground;
                    playerTwoHandList[i].ForeColor = newGame.playersList[1].PlayerCardHand[i].CardForecolor;
                    playerTwoHandList[i].Enabled = true;
                    playerTwoHandList[i].Visible = true;
                }
            }
            for (int i = 0; i < newGame.playersList[2].PlayerCardHand.Count(); i++)
            {
                if (newGame.playersList[2].PlayerCardHand[i].Cardname == "DummyCard")
                {
                    playerThreeHandList[i].Enabled = false;
                    playerThreeHandList[i].Visible = false;
                }
                else
                {
                    playerThreeHandList[i].Text = newGame.playersList[2].PlayerCardHand[i].Cardname;
                    playerThreeHandList[i].BackColor = newGame.playersList[2].PlayerCardHand[i].CardBackground;
                    playerThreeHandList[i].ForeColor = newGame.playersList[2].PlayerCardHand[i].CardForecolor;
                    playerThreeHandList[i].Enabled = true;
                    playerThreeHandList[i].Visible = true;
                }
            }
            for (int i = 0; i < newGame.playersList[3].PlayerCardHand.Count(); i++)
            {
                if (newGame.playersList[3].PlayerCardHand[i].Cardname == "DummyCard")
                {
                    playerFourHandList[i].Enabled = false;
                    playerFourHandList[i].Visible = false;
                }
                else
                {
                    playerFourHandList[i].Text = newGame.playersList[3].PlayerCardHand[i].Cardname;
                    playerFourHandList[i].BackColor = newGame.playersList[3].PlayerCardHand[i].CardBackground;
                    playerFourHandList[i].ForeColor = newGame.playersList[3].PlayerCardHand[i].CardForecolor;
                    playerFourHandList[i].Enabled = true;
                    playerFourHandList[i].Visible = true;
                }
            }
        }
        #endregion
        //deals cards to each player
        #region deal initial hand
        private void DealInitialHand()
        {
            rtbGameHistory.AppendText("Dealing initial player hands...\n");
            rtbGameHistory.ScrollToCaret();
            gameAdvDeck.ShuffleInPlace();
            int cardsToDeal = 2;
            int playerOneLabelLocation = 0;
            int playerTwoLabelLocation = 0;
            int playerThreeLabelLocation = 0;
            int playerFourLabelLocation = 0;
            for (int i = 0; i <= 3; ++i)
            {
                cardsToDeal = 2;
                for (int j = 0; j < cardsToDeal; j++)
                {
                    if (gameAdvDeck[0].IswatersRise)
                    {
                        gameAdvDeck.ShuffleInPlace();
                        cardsToDeal++;
                    }
                    else
                    {
                        newGame.playersList[i].PlayerCardHand.Add(gameAdvDeck[0]);
                        if (i == 0)
                        {
                            playerOneHandList[playerOneLabelLocation].Text = newGame.playersList[0].PlayerCardHand[playerOneLabelLocation].Cardname;
                            playerOneHandList[playerOneLabelLocation].ForeColor = newGame.playersList[0].PlayerCardHand[playerOneLabelLocation].CardForecolor;
                            playerOneHandList[playerOneLabelLocation].BackColor = newGame.playersList[0].PlayerCardHand[playerOneLabelLocation].CardBackground;
                            playerOneLabelLocation++;
                        }
                        else if (i == 1)
                        {
                            playerTwoHandList[playerTwoLabelLocation].Text = newGame.playersList[1].PlayerCardHand[playerTwoLabelLocation].Cardname;
                            playerTwoHandList[playerTwoLabelLocation].ForeColor = newGame.playersList[1].PlayerCardHand[playerTwoLabelLocation].CardForecolor;
                            playerTwoHandList[playerTwoLabelLocation].BackColor = newGame.playersList[1].PlayerCardHand[playerTwoLabelLocation].CardBackground;
                            playerTwoLabelLocation++;
                        }
                        else if (i == 2)
                        {
                            playerThreeHandList[playerThreeLabelLocation].Text = newGame.playersList[2].PlayerCardHand[playerThreeLabelLocation].Cardname;
                            playerThreeHandList[playerThreeLabelLocation].ForeColor = newGame.playersList[2].PlayerCardHand[playerThreeLabelLocation].CardForecolor;
                            playerThreeHandList[playerThreeLabelLocation].BackColor = newGame.playersList[2].PlayerCardHand[playerThreeLabelLocation].CardBackground;
                            playerThreeLabelLocation++;
                        }
                        else if (i == 3)
                        {
                            playerFourHandList[playerFourLabelLocation].Text = newGame.playersList[3].PlayerCardHand[playerFourLabelLocation].Cardname;
                            playerFourHandList[playerFourLabelLocation].ForeColor = newGame.playersList[3].PlayerCardHand[playerFourLabelLocation].CardForecolor;
                            playerFourHandList[playerFourLabelLocation].BackColor = newGame.playersList[3].PlayerCardHand[playerFourLabelLocation].CardBackground;
                            playerFourLabelLocation++;
                        }
                        gameAdvDeck.RemoveAt(0);
                    }
                }
            }
            //deal dummy cards to fill each player's hand
            for (int i = 0; i <= 3; i++)
            {
                for (int j = 0; j <= 3; j++)
                {
                    newGame.playersList[i].PlayerCardHand.Add(dummyCard);
                }
            }
            setDeckLabels();
        }
        #endregion
        //draws two cards for active player, checks for discard and reshuffle adventure deck
        #region doAdventurCardsPhase
        public void doAdventureCardsPhase()
        {
            AdventureDeck tempCard = new AdventureDeck();
            bool indexAssigned;
            int insertIndex;

            rtbGameHistory.AppendText("****Start Player Draw Phase****\n");
            rtbGameHistory.ScrollToCaret();
            lblBannerText.Text = "Player Draw Phase";
            mustDiscard = false;
            countDrawnCards = 0;
            secondAdvCardDrawn = false;
            for (int i = 0; i <= 1; i++)
            {
                indexAssigned = false;
                insertIndex = -1;
                if (!mustDiscard)
                {
                    //rtbGameHistory.AppendText("Drawing top adventure card...\n");
                    if (gameAdvDeck[0].IswatersRise)
                    {
                        player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                        player.Play();
                        System.Threading.Thread.Sleep(sleepDuration - 300);
                        lblBannerText.Text = "<<<<----Waters Rise!---->>>>";
                        rtbGameHistory.AppendText("Waters Rise was drawn!\n");
                        rtbGameHistory.AppendText("-->Water level increases!\n");
                        rtbGameHistory.ScrollToCaret();
                        player.SoundLocation = Environment.CurrentDirectory + "\\very_scary_1.wav";
                        player.Play();
                        System.Threading.Thread.Sleep(watersRiseDuration);
                        countDrawnCards++;
                        currentWaterLevel++;
                        setWaterLevel(currentWaterLevel);
                        shufflePlaceDiscardIntoPlaces();
                        System.Threading.Thread.Sleep(sleepDuration - 300);
                        backgroundPlayer.PlayLooping();
                        pbAdventureDiscard.BackColor = gameAdvDeck[0].CardBackground;
                        lblAdventureCardDiscardName.Text = gameAdvDeck[0].Cardname;
                        rtbGameHistory.AppendText("--> Waters rise card is placed onto the adventure deck discard pile.\n");
                        rtbGameHistory.ScrollToCaret();
                        player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                        player.Play();
                        System.Threading.Thread.Sleep(sleepDuration - 300);
                        gameAdvDiscard.Add(gameAdvDeck[0]);
                        gameAdvDeck.RemoveAt(0);
                        if (gameAdvDeck.Count == 0)
                        {
                            shuffleAdventureDeck();
                        }
                    }
                    else
                    {
                        for (int k = 0; k <= 5; k++)
                        {
                            if (newGame.playersList[currentPlayer].PlayerCardHand[k].Cardname == "DummyCard")
                            {
                                if (!indexAssigned)
                                {
                                    insertIndex = k;
                                    indexAssigned = true;
                                }
                            }
                        }
                        player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                        player.Play();
                        System.Threading.Thread.Sleep(sleepDuration - 300);
                        newGame.playersList[currentPlayer].PlayerCardHand[insertIndex] = gameAdvDeck[0];
                        rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " draws " +
                            gameAdvDeck[0].Cardname + "!\n");
                        updatePlayerHands();
                        rtbGameHistory.ScrollToCaret();
                        System.Threading.Thread.Sleep(sleepDuration - 300);
                        gameAdvDeck.RemoveAt(0);
                        countDrawnCards++;
                        if (countDrawnCards == 2)
                            secondAdvCardDrawn = true;
                        if (gameAdvDeck.Count == 0)
                        {
                            shuffleAdventureDeck();
                        }
                        
                        if (newGame.playersList[currentPlayer].PlayerCardHand[5].Cardname != "DummyCard")
                        {
                            lblBannerText.Text = "Player " + newGame.playersList[currentPlayer].PlayerName +
                            " now has 6 cards and must discard.  Please click one of the cards in your hand to discard.";
                            mustDiscard = true;
                        }
                        setDeckLabels();
                    }
                }
            }
            if (!mustDiscard)
            {
                btnNextPhase.Enabled = true;
                lblBannerText.Text = "Click the continue button to proceed to flood phase.";
                nextPhaseMode = true;
                if (gameAdvDeck.Count == 0)
                {
                    shuffleAdventureDeck();
                }
                updatePlayerHands();
                rtbGameHistory.AppendText("****End of Player Draw Phase****\n");
                rtbGameHistory.ScrollToCaret();
                backgroundPlayer.PlayLooping();
                drawPhaseCompleted = true;
                btnResetTurn.Enabled = false;
            }
        }
        #endregion
        //rotates player to next person and sets ui and variables correctly
        #region get next player
        private void GetNextPlayer()
        {
            if (currentPlayer == 0)
            {
                lblPlayerOne.BackColor = Color.DarkGray;
                lblPlayerOneName.BackColor = Color.DarkGray;
                lblPlayerOneSpecial.BackColor = Color.DarkGray;
                pnlPlayerOne.BackColor = Color.DarkGray;
                lblPlayerTwo.BackColor = Color.Goldenrod;
                lblPlayerTwoName.BackColor = Color.Goldenrod;
                lblPlayerTwoSpecial.BackColor = Color.Goldenrod;
                pnlPlayerTwo.BackColor = Color.Goldenrod;
                currentPlayer = 1;
                lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " is up!\n";
                rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " is up!\n");
                rtbGameHistory.ScrollToCaret();
                radSpecial.Enabled = true;
            }
            else if (currentPlayer == 1)
            {
                lblPlayerTwo.BackColor = Color.DarkGray;
                lblPlayerTwoName.BackColor = Color.DarkGray;
                lblPlayerTwoSpecial.BackColor = Color.DarkGray;
                pnlPlayerTwo.BackColor = Color.DarkGray;
                lblPlayerThree.BackColor = Color.Goldenrod;
                lblPlayerThreeName.BackColor = Color.Goldenrod;
                lblPlayerThreeSpecial.BackColor = Color.Goldenrod;
                pnlPlayerThree.BackColor = Color.Goldenrod;
                currentPlayer = 2;
                lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " is up!\n";
                rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " is up!\n");
                rtbGameHistory.ScrollToCaret();
                radSpecial.Enabled = true;
            }
            else if (currentPlayer == 2)
            {
                lblPlayerThree.BackColor = Color.DarkGray;
                lblPlayerThreeName.BackColor = Color.DarkGray;
                lblPlayerThreeSpecial.BackColor = Color.DarkGray;
                pnlPlayerThree.BackColor = Color.DarkGray;
                lblPlayerFour.BackColor = Color.Goldenrod;
                lblPlayerFourName.BackColor = Color.Goldenrod;
                lblPlayerFourSpecial.BackColor = Color.Goldenrod;
                pnlPlayerFour.BackColor = Color.Goldenrod;
                currentPlayer = 3;
                lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " is up!\n";
                rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " is up!\n");
                rtbGameHistory.ScrollToCaret();
                radSpecial.Enabled = false;
            }
            else if (currentPlayer == 3)
            {
                lblPlayerFour.BackColor = Color.DarkGray;
                lblPlayerFourName.BackColor = Color.DarkGray;
                lblPlayerFourSpecial.BackColor = Color.DarkGray;
                pnlPlayerFour.BackColor = Color.DarkGray;
                lblPlayerOne.BackColor = Color.Goldenrod;
                lblPlayerOneName.BackColor = Color.Goldenrod;
                lblPlayerOneSpecial.BackColor = Color.Goldenrod;
                pnlPlayerOne.BackColor = Color.Goldenrod;
                currentPlayer = 0;
                lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " is up!\n";
                rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " is up!\n");
                rtbGameHistory.ScrollToCaret();
                radSpecial.Enabled = true;
            }
            player.SoundLocation = Environment.CurrentDirectory + "\\playerturn.wav";
            player.Play();
            System.Threading.Thread.Sleep(sleepDuration+500);
            backgroundPlayer.PlayLooping();
            btnActionSubmit.Enabled = true;
            btnCancel.Enabled = true;
            btnEndTurn.Enabled = true;
            remainingMoves = 3;
            radClaim.Enabled = false;
            gbTurn.Text = newGame.playersList[currentPlayer].PlayerName + "'s Available Actions";
            lblSpecialDisplay.Text = newGame.playersList[currentPlayer].ActionText;
            lblSpecialDisplay.ForeColor = newGame.playersList[currentPlayer].PlayerColor;
            lblActionsRemaining.Text = remainingMoves.ToString();
            playersFound = false;
            for (int i = 0; i <= 3; i++)
            {
                if ((newGame.playersList[i].CurrentLocation == newGame.playersList[currentPlayer].CurrentLocation) && (i != currentPlayer))
                {
                    playersFound = true;
                }
            }
            if (playersFound)
                radTrade.Enabled = true;
            else
            {
                radTrade.Enabled = false;
                radMove.Checked = true;
            }
            drawPhaseCompleted = false;
            saveGameState();
        }
        //test button
        private void btnPlayerTest_Click(object sender, EventArgs e)
        {
            GetNextPlayer();
        }
        #endregion
        //create event handlers
        #region set event handlers
        private void setHandlers()
        {
            if (!handlersSet)
            for (int i = 0; i <= tilePanelList.Count - 1; i++)
            {
                tilePanelList[i].forePanel.Click += new System.EventHandler(ClickHandler);
                tilePanelList[i].forePanel.MouseEnter += new System.EventHandler(MouseEnterHandler);
                tilePanelList[i].forePanel.MouseLeave += new System.EventHandler(MouseOutHandler);
                //tilePanelList[i].forePanel.Controls[0].Click += new System.EventHandler(ClickHandler);
                tilePanelList[i].forePanel.Controls[1].Click += new System.EventHandler(PictureBoxClickHandler);
                tilePanelList[i].forePanel.Controls[2].Click += new System.EventHandler(PictureBoxClickHandler);
                tilePanelList[i].forePanel.Controls[3].Click += new System.EventHandler(PictureBoxClickHandler);
                tilePanelList[i].forePanel.Controls[4].Click += new System.EventHandler(PictureBoxClickHandler);
                //tilePanelList[i].forePanel.Controls[0].MouseEnter += new System.EventHandler(PictureBoxMouseEnterHandler);
                tilePanelList[i].forePanel.Controls[1].MouseEnter += new System.EventHandler(PictureBoxMouseEnterHandler);
                tilePanelList[i].forePanel.Controls[2].MouseEnter += new System.EventHandler(PictureBoxMouseEnterHandler);
                tilePanelList[i].forePanel.Controls[3].MouseEnter += new System.EventHandler(PictureBoxMouseEnterHandler);
                tilePanelList[i].forePanel.Controls[4].MouseEnter += new System.EventHandler(PictureBoxMouseEnterHandler);

                //tilePanelList[i].forePanel.Controls[0].MouseLeave += new System.EventHandler(PictureBoxMouseOutHandler);
                tilePanelList[i].forePanel.Controls[1].MouseLeave += new System.EventHandler(PictureBoxMouseOutHandler);
                tilePanelList[i].forePanel.Controls[2].MouseLeave += new System.EventHandler(PictureBoxMouseOutHandler);
                tilePanelList[i].forePanel.Controls[3].MouseLeave += new System.EventHandler(PictureBoxMouseOutHandler);
                tilePanelList[i].forePanel.Controls[4].MouseLeave += new System.EventHandler(PictureBoxMouseOutHandler);

                playerHandList[i].MouseEnter += new System.EventHandler(adventureCard_MouseEnter);
                playerHandList[i].MouseLeave += new System.EventHandler(adventureCard_MouseOut);
                playerHandList[i].Click += new System.EventHandler(playerHandClickHandler_Click);
                handlersSet = true;
            }
        }
        #endregion
        //click handler - manages movement and shoring up of tiles
        #region panel click handler

        private void ClickHandler(System.Object sender, System.EventArgs e)
        {
            Panel currentPanel = (Panel)sender;
            int currentPanelLocation = -1;

            for (int i = 0; i <= 23; i++)
            {
                if (currentPanel == tilePanelList[i].forePanel)
                {
                    currentPanelLocation = i;
                }
            }
            //checks what mode game is currently in
            if (moveMode)
            {
                for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                {
                    //checks if current move is valid
                    if (currentValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[currentPlayer].CurrentLocation)
                    {
                        tilePanelList[newGame.playersList[currentPlayer].CurrentLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                        tilePanelList[currentPanelLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                            newGame.playersList[currentPlayer].PlayerToken;
                        newGame.playersList[currentPlayer].CurrentLocation = currentPanelLocation;
                        lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " moves to " + gameTiles[currentPanelLocation].Name + "!";
                        rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " moves to " + gameTiles[currentPanelLocation].Name + "!\n");
                        rtbGameHistory.ScrollToCaret();
                        player.SoundLocation = Environment.CurrentDirectory + "\\bell_tree_short.wav";
                        player.Play();
                        Thread.Sleep(sleepDuration);
                        backgroundPlayer.PlayLooping();
                        takeAction();
                        moveMode = false;
                        checkResetTurn();
                        displayCurrentPhase();
                    }
                }
                playersFound = false;
                for (int i = 0; i <= 3; i++)
                {
                    if ((newGame.playersList[i].CurrentLocation == currentPanelLocation) && (i != currentPlayer))
                    {
                        playersFound = true;
                    }
                }
                if (playersFound)
                    radTrade.Enabled = true;
                else
                {
                    radTrade.Enabled = false;
                    radMove.Checked = true;
                }
                checkTreasureClaim();
            }
            else if (explorerMoveMode)
            {
                for (int j = 0; j <= explorerValidMoves.Count() - 1; j++)
                {
                    if (explorerValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[currentPlayer].CurrentLocation)
                    {
                        tilePanelList[newGame.playersList[currentPlayer].CurrentLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                        tilePanelList[currentPanelLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                            newGame.playersList[currentPlayer].PlayerToken;
                        newGame.playersList[currentPlayer].CurrentLocation = currentPanelLocation;
                        lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " moves to " + gameTiles[currentPanelLocation].Name + "!";
                        rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " moves to " + gameTiles[currentPanelLocation].Name + "!\n");
                        rtbGameHistory.ScrollToCaret();
                        player.SoundLocation = Environment.CurrentDirectory + "\\bell_tree_short.wav";
                        player.Play();
                        Thread.Sleep(sleepDuration);
                        backgroundPlayer.PlayLooping();
                        takeAction();
                        explorerMoveMode = false;
                        checkResetTurn();
                        displayCurrentPhase();
                    }
                }
                playersFound = false;
                for (int i = 0; i <= 3; i++)
                {
                    if ((newGame.playersList[i].CurrentLocation == currentPanelLocation) && (i != currentPlayer))
                    {
                        playersFound = true;
                    }
                }
                if (playersFound)
                    radTrade.Enabled = true;
                else
                {
                    radTrade.Enabled = false;
                    radMove.Checked = true;
                }
                checkTreasureClaim();
            }
            else if (shoreUpMode)
            {
                for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                {
                    if (currentValidMoves[j] == currentPanelLocation || currentPanelLocation == newGame.playersList[currentPlayer].CurrentLocation)
                    {
                        if (gameTiles[currentPanelLocation].wStatus == "Flooded")
                        {
                            tilePanelList[currentPanelLocation].forePanel.BackColor = gameTiles[currentPanelLocation].tColor;
                            tilePanelList[currentPanelLocation].backPanel.Visible = true;
                            tilePanelList[currentPanelLocation].forePanel.BackgroundImage = null;
                            gameTiles[currentPanelLocation].wStatus = "Dry";
                            
                            lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!";
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!\n");
                            rtbGameHistory.ScrollToCaret();
                            player.SoundLocation = Environment.CurrentDirectory + "\\sawsound.wav";
                            player.Play();
                            Thread.Sleep(sleepDuration);
                            backgroundPlayer.PlayLooping();
                            takeAction();
                            shoreUpMode = false;
                            checkResetTurn();
                        }
                        displayCurrentPhase();
                    }
                }
            }
            else if (explorerShoreUpMode)
            {
                {
                    for (int j = 0; j <= explorerValidMoves.Count() - 1; j++)
                    {
                        if (explorerValidMoves[j] == currentPanelLocation || currentPanelLocation == newGame.playersList[currentPlayer].CurrentLocation)
                        {
                            if (gameTiles[currentPanelLocation].wStatus == "Flooded")
                            {
                                tilePanelList[currentPanelLocation].forePanel.BackColor = gameTiles[currentPanelLocation].tColor;
                                tilePanelList[currentPanelLocation].backPanel.Visible = true;
                                tilePanelList[currentPanelLocation].forePanel.BackgroundImage = null;
                                gameTiles[currentPanelLocation].wStatus = "Dry";

                                lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!";
                                rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\sawsound.wav";
                                player.Play();
                                Thread.Sleep(sleepDuration);
                                backgroundPlayer.PlayLooping();
                                takeAction();
                                explorerShoreUpMode = false;
                                checkResetTurn();
                            }
                            displayCurrentPhase();
                        }
                    }
                }
            }
            else if (sandbagsMode)
            {
                if (gameTiles[currentPanelLocation].wStatus == "Flooded")
                {
                    tilePanelList[currentPanelLocation].forePanel.BackColor = gameTiles[currentPanelLocation].tColor;
                    tilePanelList[currentPanelLocation].backPanel.Visible = true;
                    tilePanelList[currentPanelLocation].forePanel.BackgroundImage = null;
                    gameTiles[currentPanelLocation].wStatus = "Dry";
                    lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!";
                    rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!\n");
                    rtbGameHistory.ScrollToCaret();
                    player.SoundLocation = Environment.CurrentDirectory + "\\sawsound.wav";
                    player.Play();
                    Thread.Sleep(sleepDuration);
                    backgroundPlayer.PlayLooping();
                    discardUsedAdventureCard(adventureCardLabelLocation);

                    if (playerPlayingCard == 0)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation] = dummyCard;
                    else if (playerPlayingCard == 1)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 6] = dummyCard;
                    else if (playerPlayingCard == 2)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 12] = dummyCard;
                    else if (playerPlayingCard == 3)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 18] = dummyCard;
                    updatePlayerHands();
                    sandbagsMode = false;
                    displayCurrentPhase();
                    setDeckLabels();
                }
            }
            else if (specialMode)
            {
                if (specialPlayer == "Pilot")
                {
                    tilePanelList[newGame.playersList[currentPlayer].CurrentLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                    tilePanelList[currentPanelLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                        newGame.playersList[currentPlayer].PlayerToken;
                    newGame.playersList[currentPlayer].CurrentLocation = currentPanelLocation;
                    lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " flies to " + gameTiles[currentPanelLocation].Name + "!";
                    rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " flies to " + gameTiles[currentPanelLocation].Name + "!\n");
                    rtbGameHistory.ScrollToCaret();
                    player.SoundLocation = Environment.CurrentDirectory + "\\flyby.wav";
                    player.Play();
                    Thread.Sleep(sleepDuration);
                    backgroundPlayer.PlayLooping();
                    pilotSpecialUsed = true;
                    takeAction();
                    specialMode = false;
                    checkResetTurn();
                    playersFound = false;
                    lblSpecialDisplay.ForeColor = Color.Gray;
                    radSpecial.Enabled = false;
                    for (int i = 0; i <= 3; i++)
                    {
                        if ((newGame.playersList[i].CurrentLocation == currentPanelLocation) && (i != currentPlayer))
                        {
                            playersFound = true;
                        }
                    }
                    if (playersFound)
                        radTrade.Enabled = true;
                    else
                    {
                        radTrade.Enabled = false;
                        radMove.Checked = true;
                    }
                    checkTreasureClaim();
                    displayCurrentPhase();
                }
                else if (specialPlayer == "Engineer")
                {
                    resetCurrentValidMoves();
                    currentValidMoves = findCurrentValidMoves(newGame.playersList[0].CurrentLocation);
                    engineerValidShoreUp = false;
                    for (int q = 0; q <= currentValidMoves.Count()-1; q++)
                    {
                        if (currentValidMoves[q] == currentPanelLocation)
                            engineerValidShoreUp = true;
                    }
                    if (currentPanelLocation == newGame.playersList[0].CurrentLocation)
                        engineerValidShoreUp = true;
                    if (shoredTiles == 0)
                    {
                        if (gameTiles[currentPanelLocation].wStatus == "Flooded" && engineerValidShoreUp)
                        {
                            tilePanelList[currentPanelLocation].forePanel.BackColor = gameTiles[currentPanelLocation].tColor;
                            tilePanelList[currentPanelLocation].backPanel.Visible = true;
                            tilePanelList[currentPanelLocation].forePanel.BackgroundImage = null;
                            gameTiles[currentPanelLocation].wStatus = "Dry";
                            lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!";
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!\n");
                            rtbGameHistory.ScrollToCaret();
                            player.SoundLocation = Environment.CurrentDirectory + "\\engineersaw.wav";
                            player.Play();
                            Thread.Sleep(sleepDuration);
                            backgroundPlayer.PlayLooping();
                            lblBannerText.Text = "Click the second tile to shore up.";
                            shoredTiles++;
                        }
                    }
                    else if (shoredTiles == 1)
                    {
                        if (gameTiles[currentPanelLocation].wStatus == "Flooded" && engineerValidShoreUp)
                        {
                            tilePanelList[currentPanelLocation].forePanel.BackColor = gameTiles[currentPanelLocation].tColor;
                            tilePanelList[currentPanelLocation].backPanel.Visible = true;
                            tilePanelList[currentPanelLocation].forePanel.BackgroundImage = null;
                            gameTiles[currentPanelLocation].wStatus = "Dry";
                            lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!";
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPanelLocation].Name + "!\n");
                            rtbGameHistory.ScrollToCaret();
                            player.SoundLocation = Environment.CurrentDirectory + "\\engineersaw.wav";
                            player.Play();
                            Thread.Sleep(sleepDuration);
                            backgroundPlayer.PlayLooping();
                            takeAction();
                            specialMode = false;
                            checkResetTurn();
                            displayCurrentPhase();
                        }
                    }
                }
                else if (specialPlayer == "Navigator")
                {
                    if (!playerTokenClicked)
                    {
                    }
                    else if (!navFirstMove && playerTokenClicked)
                    {
                        for (int i = 0; i <= 3; i++)
                        {
                            if (newGame.ValidMoves[newGame.playersList[playerIndexClicked].CurrentLocation, i] != -1)
                            {
                                currentValidMoves[i] = newGame.ValidMoves[newGame.playersList[playerIndexClicked].CurrentLocation, i];
                            }
                        }
                        for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                        {
                            if (currentValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[playerIndexClicked].CurrentLocation)
                            {
                                tilePanelList[newGame.playersList[playerIndexClicked].CurrentLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage = null;
                                tilePanelList[currentPanelLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage =
                                    newGame.playersList[playerIndexClicked].PlayerToken;
                                newGame.playersList[playerIndexClicked].CurrentLocation = currentPanelLocation;
                                lblBannerText.Text = newGame.playersList[playerIndexClicked].PlayerName + " moves to " + gameTiles[currentPanelLocation].Name + "!";
                                rtbGameHistory.AppendText(newGame.playersList[playerIndexClicked].PlayerName + " moves to " + gameTiles[currentPanelLocation].Name + "!\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\bell_tree_short.wav";
                                player.Play();
                                Thread.Sleep(sleepDuration);
                                backgroundPlayer.PlayLooping();
                                navFirstMove = true;
                                lblBannerText.Text = "Click the tile of the second move, or click the continue button to signal that you are finished.";
                                btnNextPhase.Enabled = true;
                            }
                        }
                        playersFound = false;
                        for (int i = 0; i <= 3; i++)
                        {
                            if ((newGame.playersList[i].CurrentLocation == currentPanelLocation) && (i != currentPlayer))
                            {
                                playersFound = true;
                            }
                        }
                        if (playersFound)
                            radTrade.Enabled = true;
                        else
                        {
                            radTrade.Enabled = false;
                            radMove.Checked = true;
                        }
                    }
                    else if (navFirstMove)
                    {
                        for (int i = 0; i <= 3; i++)
                        {
                            if (newGame.ValidMoves[newGame.playersList[playerIndexClicked].CurrentLocation, i] != -1)
                            {
                                currentValidMoves[i] = newGame.ValidMoves[newGame.playersList[playerIndexClicked].CurrentLocation, i];
                            }
                        }
                        for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                        {
                            if (currentValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[playerIndexClicked].CurrentLocation)
                            {
                                tilePanelList[newGame.playersList[playerIndexClicked].CurrentLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage = null;
                                tilePanelList[currentPanelLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage =
                                    newGame.playersList[playerIndexClicked].PlayerToken;
                                newGame.playersList[playerIndexClicked].CurrentLocation = currentPanelLocation;
                                lblBannerText.Text = newGame.playersList[playerIndexClicked].PlayerName + " moves to " + gameTiles[currentPanelLocation].Name + "!";
                                rtbGameHistory.AppendText(newGame.playersList[playerIndexClicked].PlayerName + " moves to " + gameTiles[currentPanelLocation].Name + "!\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\bell_tree_short.wav";
                                player.Play();
                                Thread.Sleep(sleepDuration);
                                backgroundPlayer.PlayLooping();

                                navMode = false;
                                specialMode = false;
                                navFirstMove = false;
                                playerTokenClicked = false;
                                btnNextPhase.Enabled = false;
                                takeAction();
                                checkResetTurn();
                                displayCurrentPhase();
                            }
                        }
                        playersFound = false;
                        for (int i = 0; i <= 3; i++)
                        {
                            if ((newGame.playersList[i].CurrentLocation == currentPanelLocation) && (i != currentPlayer))
                            {
                                playersFound = true;
                            }
                        }
                        if (playersFound)
                            radTrade.Enabled = true;
                        else
                        {
                            radTrade.Enabled = false;
                            radMove.Checked = true;
                        }
                    }
                }
            }
            else if (helicopterMode)
            {
                for (int i = 0; i <= 3; i++)
                {
                    if (newGame.playersList[i].CurrentLocation == currentPanelLocation)
                        liftPlayersFound = true;
                }
                if (!liftPlayersFound)
                {
                    lblBannerText.Text = "No players at that tile location.  Helicopter lift mode cancelled.";
                    rtbGameHistory.AppendText("No players at that tile location.  Helicopter lift mode cancelled.\n");
                    rtbGameHistory.ScrollToCaret();
                    helicopterMode = false;
                    liftFirstTileSelected = false;
                    liftSecondTileSelected = false;
                    liftConfirmed = false;
                }
                else if (!liftFirstTileSelected)
                {
                    liftFirstTileSelected = true;
                    int playerOne = 0;
                    int playerTwo = 0;
                    int playerThree = 0;
                    int playerFour = 0;
                    liftFirstTileLocation = currentPanelLocation;
                    HelicopterLift frmHL = new HelicopterLift(this);
                    if (newGame.playersList[0].CurrentLocation == liftFirstTileLocation)
                        playerOne = 1;
                    if (newGame.playersList[1].CurrentLocation == liftFirstTileLocation)
                        playerTwo = 1;
                    if (newGame.playersList[2].CurrentLocation == liftFirstTileLocation)
                        playerThree = 1;
                    if (newGame.playersList[3].CurrentLocation == liftFirstTileLocation)
                        playerFour = 1;
                    frmHL.setActivePlayers(playerOne, playerTwo, playerThree, playerFour);
                    frmHL.Show();
                    //hl.Activate();
                }
                else if (liftFirstTileSelected && liftConfirmed && !liftSecondTileSelected)
                {
                    liftSecondTileLocation = currentPanelLocation;
                    if (liftPlayerOne)
                    {
                        tilePanelList[newGame.playersList[0].CurrentLocation].forePanel.Controls[1].BackgroundImage = null;
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[1].BackgroundImage =
                            newGame.playersList[0].PlayerToken;
                        newGame.playersList[0].CurrentLocation = liftSecondTileLocation;
                    }
                    if (liftPlayerTwo)
                    {
                        tilePanelList[newGame.playersList[1].CurrentLocation].forePanel.Controls[2].BackgroundImage = null;
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[2].BackgroundImage =
                            newGame.playersList[1].PlayerToken;
                        newGame.playersList[1].CurrentLocation = liftSecondTileLocation;
                    }
                    if (liftPlayerThree)
                    {
                        tilePanelList[newGame.playersList[2].CurrentLocation].forePanel.Controls[3].BackgroundImage = null;
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[3].BackgroundImage =
                            newGame.playersList[2].PlayerToken;
                        newGame.playersList[2].CurrentLocation = liftSecondTileLocation;
                    }
                    if (liftPlayerFour)
                    {
                        tilePanelList[newGame.playersList[2].CurrentLocation].forePanel.Controls[3].BackgroundImage = null;
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[3].BackgroundImage =
                            newGame.playersList[3].PlayerToken;
                        newGame.playersList[2].CurrentLocation = liftSecondTileLocation;
                    }
                    rtbGameHistory.AppendText("Player(s) landed safely at target location " +
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[0].Text + ".\n");
                    rtbGameHistory.ScrollToCaret();
                    lblBannerText.Text = "Lift completed.  Continue playing.";
                    discardUsedAdventureCard(adventureCardLabelLocation);

                    if (playerPlayingCard == 0)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation] = dummyCard;
                    else if (playerPlayingCard == 1)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 6] = dummyCard;
                    else if (playerPlayingCard == 2)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 12] = dummyCard;
                    else if (playerPlayingCard == 3)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 18] = dummyCard;
                    updatePlayerHands();
                    liftPlayerOne = false;
                    liftPlayerTwo = false;
                    liftPlayerThree = false;
                    liftPlayerFour = false;
                    liftFirstTileSelected = false;
                    liftPlayersFound = false;
                    liftConfirmed = false;
                    liftSecondTileSelected = false;
                    liftFirstTileLocation = -1;
                    liftSecondTileLocation = -1;
                    helicopterMode = false;
                    playersFound = false;
                    for (int i = 0; i <= 3; i++)
                    {
                        if ((newGame.playersList[i].CurrentLocation == currentPanelLocation) && (i != currentPlayer))
                        {
                            playersFound = true;
                        }
                    }
                    if (playersFound)
                        radTrade.Enabled = true;
                    else
                    {
                        radTrade.Enabled = false;
                        radMove.Checked = true;
                    }
                    displayCurrentPhase();
                    setDeckLabels();
                    checkTreasureClaim();
                }
            }
        }
        #endregion

        #region pictureboxclickhandler
        private void PictureBoxClickHandler(System.Object sender, System.EventArgs e)
        {
            PictureBox currentPB = (PictureBox)sender;
            int currentPBLocation = -1;
            for (int i = 0; i <= 23; i++)
            {
                if (currentPB == tilePanelList[i].forePanel.Controls[1] ||
                    currentPB == tilePanelList[i].forePanel.Controls[2] ||
                    currentPB == tilePanelList[i].forePanel.Controls[3] ||
                    currentPB == tilePanelList[i].forePanel.Controls[4])
                {
                    currentPBLocation = i;
                }
            }

            if (moveMode)
            {
                for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                {
                    if (currentValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[currentPlayer].CurrentLocation)
                    {
                        tilePanelList[newGame.playersList[currentPlayer].CurrentLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                        tilePanelList[currentPBLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                            newGame.playersList[currentPlayer].PlayerToken;
                        newGame.playersList[currentPlayer].CurrentLocation = currentPBLocation;
                        lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " moves to " + gameTiles[currentPBLocation].Name + "!";
                        rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " moves to " + gameTiles[currentPBLocation].Name + "!\n");
                        rtbGameHistory.ScrollToCaret();
                        player.SoundLocation = Environment.CurrentDirectory + "\\bell_tree_short.wav";
                        lblBannerText.Focus();
                        player.Play();
                        Thread.Sleep(sleepDuration);
                        backgroundPlayer.PlayLooping();
                        takeAction();
                        checkResetTurn();
                        displayCurrentPhase();
                    }
                }
                playersFound = false;
                for (int i = 0; i <= 3; i++)
                {
                    if ((newGame.playersList[i].CurrentLocation == currentPBLocation) && (i != currentPlayer))
                    {
                        playersFound = true;
                    }
                }
                if (playersFound)
                    radTrade.Enabled = true;
                else
                {
                    radTrade.Enabled = false;
                    radMove.Checked = true;
                }
                moveMode = false;
                checkTreasureClaim();
            }
            else if (explorerMoveMode)
            {
                for (int j = 0; j <= explorerValidMoves.Count() - 1; j++)
                {
                    if (explorerValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[currentPlayer].CurrentLocation)
                    {
                        tilePanelList[newGame.playersList[currentPlayer].CurrentLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                        tilePanelList[currentPBLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                            newGame.playersList[currentPlayer].PlayerToken;
                        newGame.playersList[currentPlayer].CurrentLocation = currentPBLocation;
                        lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " moves to " + gameTiles[currentPBLocation].Name + "!";
                        rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " moves to " + gameTiles[currentPBLocation].Name + "!\n");
                        rtbGameHistory.ScrollToCaret();
                        player.SoundLocation = Environment.CurrentDirectory + "\\bell_tree_short.wav";
                        player.Play();
                        Thread.Sleep(sleepDuration);
                        backgroundPlayer.PlayLooping();
                        takeAction();
                        explorerMoveMode = false;
                        checkResetTurn();
                    }
                }
                playersFound = false;
                for (int i = 0; i <= 3; i++)
                {
                    if ((newGame.playersList[i].CurrentLocation == currentPBLocation) && (i != currentPlayer))
                    {
                        playersFound = true;
                    }
                }
                if (playersFound)
                    radTrade.Enabled = true;
                else
                {
                    radTrade.Enabled = false;
                    radMove.Checked = true;
                }
                checkTreasureClaim();
                displayCurrentPhase();
                lblBannerText.Focus();
            }
            else if (shoreUpMode)
            {
                for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                {
                    if (currentValidMoves[j] == currentPBLocation || currentPBLocation == newGame.playersList[currentPlayer].CurrentLocation)
                    {
                        if (gameTiles[currentPBLocation].wStatus == "Flooded")
                        {
                            tilePanelList[currentPBLocation].forePanel.BackColor = gameTiles[currentPBLocation].tColor;
                            tilePanelList[currentPBLocation].backPanel.Visible = true;
                            tilePanelList[currentPBLocation].forePanel.BackgroundImage = null;
                            gameTiles[currentPBLocation].wStatus = "Dry";
                            lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!";
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!\n");
                            rtbGameHistory.ScrollToCaret();
                            player.SoundLocation = Environment.CurrentDirectory + "\\sawsound.wav";
                            player.Play();
                            Thread.Sleep(sleepDuration);
                            backgroundPlayer.PlayLooping();
                            takeAction();
                            shoreUpMode = false;
                            checkResetTurn();
                        }
                        displayCurrentPhase();
                    }
                }
            }
            else if (explorerShoreUpMode)
            {
                for (int j = 0; j <= explorerValidMoves.Count() - 1; j++)
                {
                    if (explorerValidMoves[j] == currentPBLocation || currentPBLocation == newGame.playersList[currentPlayer].CurrentLocation)
                    {
                        if (gameTiles[currentPBLocation].wStatus == "Flooded")
                        {
                            tilePanelList[currentPBLocation].forePanel.BackColor = gameTiles[currentPBLocation].tColor;
                            tilePanelList[currentPBLocation].backPanel.Visible = true;
                            tilePanelList[currentPBLocation].forePanel.BackgroundImage = null;
                            gameTiles[currentPBLocation].wStatus = "Dry";
                            lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!";
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!\n");
                            rtbGameHistory.ScrollToCaret();
                            player.SoundLocation = Environment.CurrentDirectory + "\\sawsound.wav";
                            player.Play();
                            Thread.Sleep(sleepDuration);
                            backgroundPlayer.PlayLooping();
                            takeAction();
                            explorerShoreUpMode = false;
                            checkResetTurn();
                        }
                        displayCurrentPhase();
                    }
                }
            }
            else if (sandbagsMode)
            {
                if (gameTiles[currentPBLocation].wStatus == "Flooded")
                {
                    tilePanelList[currentPBLocation].forePanel.BackColor = gameTiles[currentPBLocation].tColor;
                    tilePanelList[currentPBLocation].backPanel.Visible = true;
                    tilePanelList[currentPBLocation].forePanel.BackgroundImage = null;
                    gameTiles[currentPBLocation].wStatus = "Dry";
                    lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!";
                    rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!\n");
                    rtbGameHistory.ScrollToCaret();
                    player.SoundLocation = Environment.CurrentDirectory + "\\sawsound.wav";
                    player.Play();
                    Thread.Sleep(sleepDuration);
                    backgroundPlayer.PlayLooping();
                    discardUsedAdventureCard(adventureCardLabelLocation);

                    if (playerPlayingCard == 0)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation] = dummyCard;
                    else if (playerPlayingCard == 1)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 6] = dummyCard;
                    else if (playerPlayingCard == 2)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 12] = dummyCard;
                    else if (playerPlayingCard == 3)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 18] = dummyCard;
                    updatePlayerHands();
                    sandbagsMode = false;
                    displayCurrentPhase();
                    setDeckLabels();
                }
            }
            else if (tradeMode)
            {
                //trading with player one
                if (currentPB == tilePanelList[currentPBLocation].forePanel.Controls[1])
                {
                    if (currentPlayer == tilePanelList[currentPBLocation].forePanel.Controls.GetChildIndex(currentPB) - 1)
                    {
                        lblBannerText.Text = "You can't trade with yourself! " + "Click on the token of the player with whom you'd like to trade.";
                    }
                    else
                    {
                        if (newGame.playersList[0].PlayerCardHand[4].Cardname != "DummyCard")
                        {
                            lblBannerText.Text = "Player One is at the 5 card hand limit - cannot give more cards. Trading cancelled, continue playing.";
                            System.Threading.Thread.Sleep(750);
                            btnActionSubmit.Enabled = true;
                            btnCancel.Enabled = false;
                            radMove.Checked = true;
                            tradeMode = false;
                        }
                        else if (newGame.playersList[0].CurrentLocation == tileTradeLocation)
                        {
                            lblBannerText.Text = "Trading with Player One - click the card you'd like to give.";
                            tradeWithEngineer = true;
                        }
                        else
                        {
                            lblBannerText.Text = "You can only trade with players on the same tile.  " +
                                "Please click a player token on the tile you currently occupy.";
                        }
                    }
                }
                //trading with player two
                if (currentPB == tilePanelList[currentPBLocation].forePanel.Controls[2])
                {
                    if (currentPlayer == tilePanelList[currentPBLocation].forePanel.Controls.GetChildIndex(currentPB) - 1)
                    {
                        lblBannerText.Text = "You can't trade with yourself! " + "Click on the token of the player with whom you'd like to trade.";
                    }
                    else
                    {
                        if (newGame.playersList[1].PlayerCardHand[4].Cardname != "DummyCard")
                        {
                            lblBannerText.Text = "Player Two is at the 5 card hand limit - cannot give more cards. Trading cancelled, continue playing.";
                            System.Threading.Thread.Sleep(750);
                            btnActionSubmit.Enabled = true;
                            btnCancel.Enabled = false;
                            radMove.Checked = true;
                            tradeMode = false;
                        }
                        else if (newGame.playersList[1].CurrentLocation == tileTradeLocation)
                        {
                            lblBannerText.Text = "Trading with Player Two - click the card you'd like to give.";
                            tradeWithNavigator = true;
                        }
                        else
                        {
                            lblBannerText.Text = "You can only trade with players on the same tile.  " +
                                "Please click a player token on the tile you currently occupy.";
                        }
                    }
                }
                //trading with player three
                if (currentPB == tilePanelList[currentPBLocation].forePanel.Controls[3])
                {
                    if (currentPlayer == tilePanelList[currentPBLocation].forePanel.Controls.GetChildIndex(currentPB) - 1)
                    {
                        lblBannerText.Text = "You can't trade with yourself! " + "Click on the token of the player with whom you'd like to trade.";
                    }
                    else
                    {
                        if (newGame.playersList[2].PlayerCardHand[4].Cardname != "DummyCard")
                        {
                            lblBannerText.Text = "Player three is at the 5 card hand limit - cannot give more cards. Trading cancelled, continue playing.";
                            System.Threading.Thread.Sleep(750);
                            btnActionSubmit.Enabled = true;
                            btnCancel.Enabled = false;
                            radMove.Checked = true;
                            tradeMode = false;
                        }
                        else if (newGame.playersList[2].CurrentLocation == tileTradeLocation)
                        {
                            lblBannerText.Text = "Trading with Player Three - click the card you'd like to give.";
                            tradeWithPilot = true;
                        }
                        else
                        {
                            lblBannerText.Text = "You can only trade with players on the same tile.  " +
                                "Please click a player token on the tile you currently occupy.";
                        }
                    }
                }
                //trading with player four
                if (currentPB == tilePanelList[currentPBLocation].forePanel.Controls[4])
                {
                    if (currentPlayer == tilePanelList[currentPBLocation].forePanel.Controls.GetChildIndex(currentPB) - 1)
                    {
                        lblBannerText.Text = "You can't trade with yourself!";
                        System.Threading.Thread.Sleep(750);
                        lblBannerText.Text = "Click on the token of the player with whom you'd like to trade.";
                    }
                    else
                    {
                        if (newGame.playersList[3].PlayerCardHand[4].Cardname != "DummyCard")
                        {
                            lblBannerText.Text = "Player Four is at the 5 card hand limit - cannot give more cards. Trading cancelled, continue playing.";
                            System.Threading.Thread.Sleep(750);
                            btnActionSubmit.Enabled = true;
                            btnCancel.Enabled = false;
                            radMove.Checked = true;
                            tradeMode = false;
                        }
                        else if (newGame.playersList[3].CurrentLocation == tileTradeLocation)
                        {
                            lblBannerText.Text = "Trading with Player Three - click the card you'd like to give.";
                            tradeWithExplorer = true;
                        }
                        else
                        {
                            lblBannerText.Text = "You can only trade with players on the same tile.  " +
                                "Please click a player token on the tile you currently occupy.";
                        }
                    }
                }
            }
            else if (specialMode)
            {
                if (specialPlayer == "Pilot")
                {
                    tilePanelList[newGame.playersList[currentPlayer].CurrentLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                    tilePanelList[currentPBLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                        newGame.playersList[currentPlayer].PlayerToken;
                    newGame.playersList[currentPlayer].CurrentLocation = currentPBLocation;
                    lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " flies to " + gameTiles[currentPBLocation].Name + "!";
                    rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " flies to " + gameTiles[currentPBLocation].Name + "!\n");
                    rtbGameHistory.ScrollToCaret();
                    player.SoundLocation = Environment.CurrentDirectory + "\\flyby.wav";
                    player.Play();
                    Thread.Sleep(sleepDuration);
                    backgroundPlayer.PlayLooping();
                    pilotSpecialUsed = true;
                    takeAction();
                    specialMode = false;
                    checkResetTurn();
                    playersFound = false;
                    radSpecial.Enabled = false;
                    lblSpecialDisplay.ForeColor = Color.Gray;
                    for (int i = 0; i <= 3; i++)
                    {
                        if ((newGame.playersList[i].CurrentLocation == currentPBLocation) && (i != currentPlayer))
                        {
                            playersFound = true;
                        }
                    }
                    if (playersFound)
                        radTrade.Enabled = true;
                    else
                    {
                        radTrade.Enabled = false;
                        radMove.Checked = true;
                    }
                    checkTreasureClaim();
                    displayCurrentPhase();
                }
                else if (specialPlayer == "Engineer")
                {
                    resetCurrentValidMoves();
                    currentValidMoves = findCurrentValidMoves(newGame.playersList[0].CurrentLocation);
                    engineerValidShoreUp = false;
                    for (int q = 0; q <= currentValidMoves.Count()-1; q++)
                    {
                        if (currentValidMoves[q] == currentPBLocation)
                            engineerValidShoreUp = true;
                    }
                    if (currentPBLocation == newGame.playersList[0].CurrentLocation)
                        engineerValidShoreUp = true;

                    if (shoredTiles == 0)
                    {
                        if (gameTiles[currentPBLocation].wStatus == "Flooded" && engineerValidShoreUp)
                        {
                            tilePanelList[currentPBLocation].forePanel.BackColor = gameTiles[currentPBLocation].tColor;
                            tilePanelList[currentPBLocation].backPanel.Visible = true;
                            tilePanelList[currentPBLocation].forePanel.BackgroundImage = null;
                            gameTiles[currentPBLocation].wStatus = "Dry";
                            lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!";
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!\n");
                            rtbGameHistory.ScrollToCaret();
                            player.SoundLocation = Environment.CurrentDirectory + "\\engineersaw.wav";
                            player.Play();
                            Thread.Sleep(sleepDuration);
                            backgroundPlayer.PlayLooping();
                            lblBannerText.Text = "Click the second tile to shore up.";
                            shoredTiles++;
                        }
                    }
                    else if (shoredTiles == 1)
                    {
                        if (gameTiles[currentPBLocation].wStatus == "Flooded" && engineerValidShoreUp)
                        {
                            tilePanelList[currentPBLocation].forePanel.BackColor = gameTiles[currentPBLocation].tColor;
                            tilePanelList[currentPBLocation].backPanel.Visible = true;
                            tilePanelList[currentPBLocation].forePanel.BackgroundImage = null;
                            gameTiles[currentPBLocation].wStatus = "Dry";
                            lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!";
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " shores up " + gameTiles[currentPBLocation].Name + "!\n");
                            rtbGameHistory.ScrollToCaret();
                            player.SoundLocation = Environment.CurrentDirectory + "\\engineersaw.wav";
                            player.Play();
                            Thread.Sleep(sleepDuration);
                            backgroundPlayer.PlayLooping();
                            takeAction();
                            specialMode = false;
                            checkResetTurn();
                            displayCurrentPhase();
                        }
                    }
                }
                else if (specialPlayer == "Navigator")
                {
                    if (!playerTokenClicked)
                    {
                        //if engineer clicked
                        if (currentPB == tilePanelList[currentPBLocation].forePanel.Controls[1] &&
                            newGame.playersList[0].CurrentLocation == currentPBLocation)
                        {
                            playerIndexClicked = 0;
                            playerTokenClicked = true;
                            lblBannerText.Text = "Engineer selected.  Please click the tile of the first move.";
                        }
                        else if (currentPB == tilePanelList[currentPBLocation].forePanel.Controls[2] &&
                            newGame.playersList[1].CurrentLocation == currentPBLocation)
                        {
                            lblBannerText.Text = "Cannot move yourself using Navigator special action - please click a different player token.";
                        }
                        else if (currentPB == tilePanelList[currentPBLocation].forePanel.Controls[3] &&
                            newGame.playersList[2].CurrentLocation == currentPBLocation)
                        {
                            playerIndexClicked = 2;
                            playerTokenClicked = true;
                            lblBannerText.Text = "Pilot selected.  Please click the tile of the first move.";
                        }
                        else if (currentPB == tilePanelList[currentPBLocation].forePanel.Controls[4] &&
                            newGame.playersList[3].CurrentLocation == currentPBLocation)
                        {
                            playerIndexClicked = 3;
                            playerTokenClicked = true;
                            lblBannerText.Text = "Explorer selected.  Please click the tile of the first move.";
                        }
                    }
                    else if (!navFirstMove && playerTokenClicked)
                    {
                        for (int i = 0; i <= 3; i++)
                        {
                            if (newGame.ValidMoves[newGame.playersList[playerIndexClicked].CurrentLocation, i] != -1)
                            {
                                currentValidMoves[i] = newGame.ValidMoves[newGame.playersList[playerIndexClicked].CurrentLocation, i];
                            }
                        }
                        for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                        {
                            if (currentValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[playerIndexClicked].CurrentLocation)
                            {
                                tilePanelList[newGame.playersList[playerIndexClicked].CurrentLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage = null;
                                tilePanelList[currentPBLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage =
                                    newGame.playersList[playerIndexClicked].PlayerToken;
                                newGame.playersList[playerIndexClicked].CurrentLocation = currentPBLocation;
                                lblBannerText.Text = newGame.playersList[playerIndexClicked].PlayerName + " moves to " + gameTiles[currentPBLocation].Name + "!";
                                rtbGameHistory.AppendText(newGame.playersList[playerIndexClicked].PlayerName + " moves to " + gameTiles[currentPBLocation].Name + "!\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\bell_tree_short.wav";
                                player.Play();
                                Thread.Sleep(sleepDuration);
                                backgroundPlayer.PlayLooping();
                                navFirstMove = true;
                                lblBannerText.Text = "Click the tile of the second move, or click the continue button to signal that you are finished.";
                                btnNextPhase.Enabled = true;
                            }
                            playersFound = false;
                            for (int i = 0; i <= 3; i++)
                            {
                                if ((newGame.playersList[i].CurrentLocation == currentPBLocation) && (i != currentPlayer))
                                {
                                    playersFound = true;
                                }
                            }
                            if (playersFound)
                                radTrade.Enabled = true;
                            else
                            {
                                radTrade.Enabled = false;
                                radMove.Checked = true;
                            }
                            moveMode = false;
                        }
                    }
                    else if (navFirstMove)
                    {
                        for (int i = 0; i <= 3; i++)
                        {
                            if (newGame.ValidMoves[newGame.playersList[playerIndexClicked].CurrentLocation, i] != -1)
                            {
                                currentValidMoves[i] = newGame.ValidMoves[newGame.playersList[playerIndexClicked].CurrentLocation, i];
                            }
                        }
                        for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                        {
                            if (currentValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[playerIndexClicked].CurrentLocation)
                            {
                                tilePanelList[newGame.playersList[playerIndexClicked].CurrentLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage = null;
                                tilePanelList[currentPBLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage =
                                    newGame.playersList[playerIndexClicked].PlayerToken;
                                newGame.playersList[playerIndexClicked].CurrentLocation = currentPBLocation;
                                lblBannerText.Text = newGame.playersList[playerIndexClicked].PlayerName + " moves to " + gameTiles[currentPBLocation].Name + "!";
                                rtbGameHistory.AppendText(newGame.playersList[playerIndexClicked].PlayerName + " moves to " + gameTiles[currentPBLocation].Name + "!\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\bell_tree_short.wav";
                                player.Play();
                                Thread.Sleep(sleepDuration);
                                backgroundPlayer.PlayLooping();

                                playerTokenClicked = false;
                                navMode = false;
                                navFirstMove = false;
                                specialMode = false;
                                btnNextPhase.Enabled = false;
                                takeAction();
                                checkResetTurn();
                                playersFound = false;
                                for (int i = 0; i <= 3; i++)
                                {
                                    if ((newGame.playersList[i].CurrentLocation == currentPBLocation) && (i != playerIndexClicked))
                                    {
                                        playersFound = true;
                                    }
                                }
                                if (playersFound)
                                    radTrade.Enabled = true;
                                else
                                {
                                    radTrade.Enabled = false;
                                    radMove.Checked = true;
                                }
                                checkTreasureClaim();
                                displayCurrentPhase();
                            }
                        }
                    }
                }
            }
            else if (helicopterMode)
            {
                for (int i = 0; i <= 3; i++)
                {
                    if (newGame.playersList[i].CurrentLocation == currentPBLocation)
                        liftPlayersFound = true;
                }
                if (!liftPlayersFound)
                {
                    lblBannerText.Text = "No players at that tile location.  Helicopter lift mode cancelled.";
                    rtbGameHistory.AppendText("No players at that tile location.  Helicopter lift mode cancelled.\n");
                    rtbGameHistory.ScrollToCaret();
                    helicopterMode = false;
                    liftFirstTileSelected = false;
                    liftSecondTileSelected = false;
                    liftConfirmed = false;
                }
                else if (!liftFirstTileSelected)
                {
                    liftFirstTileSelected = true;
                    int playerOne = 0;
                    int playerTwo = 0;
                    int playerThree = 0;
                    int playerFour = 0;
                    liftFirstTileLocation = currentPBLocation;
                    HelicopterLift frmHL = new HelicopterLift(this);
                    if (newGame.playersList[0].CurrentLocation == liftFirstTileLocation)
                        playerOne = 1;
                    if (newGame.playersList[1].CurrentLocation == liftFirstTileLocation)
                        playerTwo = 1;
                    if (newGame.playersList[2].CurrentLocation == liftFirstTileLocation)
                        playerThree = 1;
                    if (newGame.playersList[3].CurrentLocation == liftFirstTileLocation)
                        playerFour = 1;
                    frmHL.setActivePlayers(playerOne, playerTwo, playerThree, playerFour);
                    frmHL.Show();
                    //hl.Activate();
                }
                else if (liftFirstTileSelected && liftConfirmed && !liftSecondTileSelected)
                {
                    liftSecondTileLocation = currentPBLocation;
                    if (liftPlayerOne)
                    {
                        tilePanelList[newGame.playersList[0].CurrentLocation].forePanel.Controls[1].BackgroundImage = null;
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[1].BackgroundImage =
                            newGame.playersList[0].PlayerToken;
                        newGame.playersList[0].CurrentLocation = liftSecondTileLocation;
                    }
                    if (liftPlayerTwo)
                    {
                        tilePanelList[newGame.playersList[1].CurrentLocation].forePanel.Controls[2].BackgroundImage = null;
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[2].BackgroundImage =
                            newGame.playersList[1].PlayerToken;
                        newGame.playersList[1].CurrentLocation = liftSecondTileLocation;
                    }
                    if (liftPlayerThree)
                    {
                        tilePanelList[newGame.playersList[2].CurrentLocation].forePanel.Controls[3].BackgroundImage = null;
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[3].BackgroundImage =
                            newGame.playersList[2].PlayerToken;
                        newGame.playersList[2].CurrentLocation = liftSecondTileLocation;
                    }
                    if (liftPlayerFour)
                    {
                        tilePanelList[newGame.playersList[3].CurrentLocation].forePanel.Controls[4].BackgroundImage = null;
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[4].BackgroundImage =
                            newGame.playersList[3].PlayerToken;
                        newGame.playersList[3].CurrentLocation = liftSecondTileLocation;
                    }
                    player.SoundLocation = Environment.CurrentDirectory + "\\flyby.wav";
                    player.Play();
                    System.Threading.Thread.Sleep(sleepDuration+500);
                    rtbGameHistory.AppendText("Player(s) landed safely at target location " +
                        tilePanelList[liftSecondTileLocation].forePanel.Controls[0].Text + ".\n");
                    rtbGameHistory.ScrollToCaret();
                    lblBannerText.Text = "Lift completed.  Continue playing.";
                    backgroundPlayer.PlayLooping();
                    discardUsedAdventureCard(adventureCardLabelLocation);

                    if (playerPlayingCard == 0)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation] = dummyCard;
                    else if (playerPlayingCard == 1)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 6] = dummyCard;
                    else if (playerPlayingCard == 2)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 12] = dummyCard;
                    else if (playerPlayingCard == 3)
                        newGame.playersList[playerPlayingCard].PlayerCardHand[adventureCardLabelLocation - 18] = dummyCard;
                    updatePlayerHands();
                    liftPlayerOne = false;
                    liftPlayerTwo = false;
                    liftPlayerThree = false;
                    liftPlayerFour = false;
                    liftFirstTileSelected = false;
                    liftPlayersFound = false;
                    liftConfirmed = false;
                    liftSecondTileSelected = false;
                    liftFirstTileLocation = -1;
                    liftSecondTileLocation = -1;
                    helicopterMode = false;
                    playersFound = false;
                    for (int i = 0; i <= 3; i++)
                    {
                        if ((newGame.playersList[i].CurrentLocation == currentPBLocation) && (i != currentPlayer))
                        {
                            playersFound = true;
                        }
                    }
                    if (playersFound)
                        radTrade.Enabled = true;
                    else
                    {
                        radTrade.Enabled = false;
                        radMove.Checked = true;
                    }
                    checkTreasureClaim();
                    displayCurrentPhase();
                    setDeckLabels();
                }
            }
        }
        #endregion

        #region playerhandclickhandler
        private void playerHandClickHandler_Click(System.Object sender, System.EventArgs e)
        {
            Label currentLabel = (Label)sender;
            int currentLabelLocation = -1;
            int tradedCardIndex = -1;
            bool cardTraded = false;

            bool indexAssigned = false;
            int insertIndex = -1;
            //find and set current label location
            for (int i = 0; i <= 23; i++)
            {
                if (currentLabel == playerHandList[i])
                {
                    currentLabelLocation = i;
                }
            }
            //sets correct card to trade index, based on label location
            if (currentLabelLocation >= 0 && currentLabelLocation <= 5)
                tradedCardIndex = currentLabelLocation;
            else if (currentLabelLocation >= 6 && currentLabelLocation <= 11)
                tradedCardIndex = currentLabelLocation - 6;
            else if (currentLabelLocation >= 12 && currentLabelLocation <= 17)
                tradedCardIndex = currentLabelLocation - 12;
            else if (currentLabelLocation >= 18)
                tradedCardIndex = currentLabelLocation - 18;
            if (mustDiscard)
            {
                if (currentLabelLocation >= 0 && currentLabelLocation <= 5)
                {
                    if (currentPlayer == 0)
                    {
                        rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " discards " +
                            newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname + ".\n");
                        rtbGameHistory.ScrollToCaret();
                        lblBannerText.Text = "Discard complete - proceed with game.";

                        //discard the card
                        gameAdvDiscard.Add(newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex]);
                        lblAdventureCardDiscardName.Text = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname;
                        lblAdventureCardDiscardName.ForeColor = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].CardForecolor;
                        pbAdventureDiscard.BackColor = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].CardBackground;

                        newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex] = dummyCard;
                        updatePlayerHands();
                        mustDiscard = false;
                        if (secondAdvCardDrawn)
                        {
                            btnNextPhase.Enabled = true;
                            rtbGameHistory.AppendText("Click the continue button to proceed to flood phase.\n");
                            rtbGameHistory.ScrollToCaret();
                        }
                        else
                        {
                            if (gameAdvDeck[0].IswatersRise)
                            {
                                player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                lblBannerText.Text = "<<<<----Waters Rise!---->>>>";
                                rtbGameHistory.AppendText("Waters Rise was drawn!\n");
                                rtbGameHistory.AppendText("-->Water level increases!\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\very_scary_1.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(watersRiseDuration);
                                currentWaterLevel++;
                                setWaterLevel(currentWaterLevel);
                                shufflePlaceDiscardIntoPlaces();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                backgroundPlayer.PlayLooping();
                                pbAdventureDiscard.BackColor = gameAdvDeck[0].CardBackground;
                                lblAdventureCardDiscardName.Text = gameAdvDeck[0].Cardname;
                                rtbGameHistory.AppendText("--> Waters rise card is placed onto the adventure deck discard pile.\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                gameAdvDiscard.Add(gameAdvDeck[0]);
                                gameAdvDeck.RemoveAt(0);
                                secondAdvCardDrawn = true;
                                countDrawnCards++;
                                if (gameAdvDeck.Count == 0)
                                {
                                    shuffleAdventureDeck();
                                }
                                SignalFloodPhase();
                            }
                            else
                            {
                                for (int k = 0; k <= 5; k++)
                                {
                                    if (newGame.playersList[currentPlayer].PlayerCardHand[k].Cardname == "DummyCard")
                                    {
                                        if (!indexAssigned)
                                        {
                                            insertIndex = k;
                                            indexAssigned = true;
                                        }
                                    }
                                }
                                player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                newGame.playersList[currentPlayer].PlayerCardHand[insertIndex] = gameAdvDeck[0];
                                rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " draws " +
                                    gameAdvDeck[0].Cardname + "!\n");
                                updatePlayerHands();
                                rtbGameHistory.ScrollToCaret();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                gameAdvDeck.RemoveAt(0);
                                secondAdvCardDrawn = true;
                                countDrawnCards++;
                                if (gameAdvDeck.Count == 0)
                                {
                                    shuffleAdventureDeck();
                                }
                                if (newGame.playersList[currentPlayer].PlayerCardHand[5].Cardname != "DummyCard")
                                {
                                    lblBannerText.Text = "Player " + newGame.playersList[currentPlayer].PlayerName +
                                    " now has 6 cards and must discard.  Please click one of the cards in your hand to discard.";
                                    btnEndTurn.Enabled = false;
                                    btnActionSubmit.Enabled = false;
                                    btnCancel.Enabled = false;
                                    btnResetTurn.Enabled = false;
                                    mustDiscard = true;
                                }
                                else
                                {
                                    SignalFloodPhase();
                                }
                            }
                        }
                        if (newGame.playersList[currentPlayer].PlayerCardHand[5].Cardname != "DummyCard")
                        {
                            lblBannerText.Text = "Player " + newGame.playersList[currentPlayer].PlayerName +
                            " now has 6 cards and must discard.  Please click one of the cards in your hand to discard.";
                            btnEndTurn.Enabled = false;
                            btnActionSubmit.Enabled = false;
                            btnCancel.Enabled = false;
                            btnResetTurn.Enabled = false;
                            mustDiscard = true;
                        }
                        setDeckLabels();
                        if (!mustDiscard)
                        {
                            btnNextPhase.Enabled = true;
                            lblBannerText.Text = "Click the continue button to proceed to flood phase.";
                            nextPhaseMode = true;
                            if (gameAdvDeck.Count == 0)
                            {
                                shuffleAdventureDeck();
                            }
                            updatePlayerHands();
                            rtbGameHistory.AppendText("****End of Player Draw Phase****\n");
                            rtbGameHistory.ScrollToCaret();
                            backgroundPlayer.PlayLooping();
                            drawPhaseCompleted = true;
                            btnResetTurn.Enabled = false;
                            secondAdvCardDrawn = false;
                        }
                    }
                    else
                    {
                        //inform player they've chosen incorrectly
                        rtbGameHistory.AppendText("You've clicked an inactive player.  Please click a card from the active player's hand to discard.");
                        rtbGameHistory.ScrollToCaret();
                    }
                }
                else if (currentLabelLocation >= 6 && currentLabelLocation <= 11)
                {
                    if (currentPlayer == 1)
                    {
                        rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " discards " +
                            newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname + ".\n");
                        rtbGameHistory.ScrollToCaret();
                        lblBannerText.Text = "Discard complete - proceed with game.";
                        //discard the card
                        gameAdvDiscard.Add(newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex]);
                        lblAdventureCardDiscardName.Text = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname;
                        lblAdventureCardDiscardName.ForeColor = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].CardForecolor;
                        pbAdventureDiscard.BackColor = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].CardBackground;

                        newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex] = dummyCard;
                        updatePlayerHands();
                        mustDiscard = false;
                        if (secondAdvCardDrawn)
                        {
                            btnNextPhase.Enabled = true;
                            rtbGameHistory.AppendText("Click the continue button to proceed to flood phase.\n");
                            rtbGameHistory.ScrollToCaret();
                        }
                        else
                        {
                            if (gameAdvDeck[0].IswatersRise)
                            {
                                player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                lblBannerText.Text = "<<<<----Waters Rise!---->>>>";
                                rtbGameHistory.AppendText("Waters Rise was drawn!\n");
                                rtbGameHistory.AppendText("-->Water level increases!\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\very_scary_1.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(watersRiseDuration);
                                currentWaterLevel++;
                                countDrawnCards++;
                                setWaterLevel(currentWaterLevel);
                                shufflePlaceDiscardIntoPlaces();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                backgroundPlayer.PlayLooping();
                                pbAdventureDiscard.BackColor = gameAdvDeck[0].CardBackground;
                                lblAdventureCardDiscardName.Text = gameAdvDeck[0].Cardname;
                                rtbGameHistory.AppendText("--> Waters rise card is placed onto the adventure deck discard pile.\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                gameAdvDiscard.Add(gameAdvDeck[0]);
                                gameAdvDeck.RemoveAt(0);
                                secondAdvCardDrawn = true;
                                if (gameAdvDeck.Count == 0)
                                {
                                    shuffleAdventureDeck();
                                }
                                SignalFloodPhase();
                            }
                            else
                            {
                                for (int k = 0; k <= 5; k++)
                                {
                                    if (newGame.playersList[currentPlayer].PlayerCardHand[k].Cardname == "DummyCard")
                                    {
                                        if (!indexAssigned)
                                        {
                                            insertIndex = k;
                                            indexAssigned = true;
                                        }
                                    }
                                }
                                player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                newGame.playersList[currentPlayer].PlayerCardHand[insertIndex] = gameAdvDeck[0];
                                rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " draws " +
                                    gameAdvDeck[0].Cardname + "!\n");
                                updatePlayerHands();
                                rtbGameHistory.ScrollToCaret();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                gameAdvDeck.RemoveAt(0);
                                countDrawnCards++;
                                secondAdvCardDrawn = true;
                                if (gameAdvDeck.Count == 0)
                                {
                                    shuffleAdventureDeck();
                                }
                                if (newGame.playersList[currentPlayer].PlayerCardHand[5].Cardname != "DummyCard")
                                {
                                    lblBannerText.Text = "Player " + newGame.playersList[currentPlayer].PlayerName +
                                    " now has 6 cards and must discard.  Please click one of the cards in your hand to discard.";
                                    btnEndTurn.Enabled = false;
                                    btnActionSubmit.Enabled = false;
                                    btnCancel.Enabled = false;
                                    btnResetTurn.Enabled = false;
                                    mustDiscard = true;
                                }
                                else
                                {
                                    SignalFloodPhase();
                                }
                            }
                        }
                        if (newGame.playersList[currentPlayer].PlayerCardHand[5].Cardname != "DummyCard")
                        {
                            lblBannerText.Text = "Player " + newGame.playersList[currentPlayer].PlayerName +
                            " now has 6 cards and must discard.  Please click one of the cards in your hand to discard.";
                            btnEndTurn.Enabled = false;
                            btnActionSubmit.Enabled = false;
                            btnCancel.Enabled = false;
                            btnResetTurn.Enabled = false;
                            mustDiscard = true;
                        }
                        setDeckLabels();
                        if (!mustDiscard)
                        {
                            btnNextPhase.Enabled = true;
                            lblBannerText.Text = "Click the continue button to proceed to flood phase.";
                            nextPhaseMode = true;
                            if (gameAdvDeck.Count == 0)
                            {
                                shuffleAdventureDeck();
                            }
                            updatePlayerHands();
                            rtbGameHistory.AppendText("****End of Player Draw Phase****\n");
                            rtbGameHistory.ScrollToCaret();
                            backgroundPlayer.PlayLooping();
                            drawPhaseCompleted = true;
                            btnResetTurn.Enabled = false;
                            secondAdvCardDrawn = false;
                        }
                    }
                    else
                    {
                        //inform player they've chosen incorrectly
                        rtbGameHistory.AppendText("You've clicked an inactive player.  Please click a card from the active player's hand to discard.");
                        rtbGameHistory.ScrollToCaret();
                    }
                }
                else if (currentLabelLocation >= 12 && currentLabelLocation <= 17)
                {
                    if (currentPlayer == 2)
                    {
                        rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " discards " +
                            newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname + ".\n");
                        lblBannerText.Text = "Discard complete - proceed with game.";
                        //discard the card
                        gameAdvDiscard.Add(newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex]);
                        lblAdventureCardDiscardName.Text = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname;
                        lblAdventureCardDiscardName.ForeColor = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].CardForecolor;
                        pbAdventureDiscard.BackColor = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].CardBackground;

                        newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex] = dummyCard;
                        updatePlayerHands();
                        mustDiscard = false;
                        if (secondAdvCardDrawn)
                        {
                            btnNextPhase.Enabled = true;
                            rtbGameHistory.AppendText("Click the continue button to proceed to flood phase.\n");
                            rtbGameHistory.ScrollToCaret();
                        }
                        else
                        {
                            if (gameAdvDeck[0].IswatersRise)
                            {
                                player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                lblBannerText.Text = "<<<<----Waters Rise!---->>>>";
                                rtbGameHistory.AppendText("Waters Rise was drawn!\n");
                                rtbGameHistory.AppendText("-->Water level increases!\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\very_scary_1.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(watersRiseDuration);
                                currentWaterLevel++;
                                countDrawnCards++;
                                setWaterLevel(currentWaterLevel);
                                shufflePlaceDiscardIntoPlaces();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                backgroundPlayer.PlayLooping();
                                pbAdventureDiscard.BackColor = gameAdvDeck[0].CardBackground;
                                lblAdventureCardDiscardName.Text = gameAdvDeck[0].Cardname;
                                rtbGameHistory.AppendText("--> Waters rise card is placed onto the adventure deck discard pile.\n");
                                rtbGameHistory.ScrollToCaret();
                                player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                gameAdvDiscard.Add(gameAdvDeck[0]);
                                gameAdvDeck.RemoveAt(0);
                                secondAdvCardDrawn = true;
                                if (gameAdvDeck.Count == 0)
                                {
                                    shuffleAdventureDeck();
                                }
                                SignalFloodPhase();
                            }
                            else
                            {
                                for (int k = 0; k <= 5; k++)
                                {
                                    if (newGame.playersList[currentPlayer].PlayerCardHand[k].Cardname == "DummyCard")
                                    {
                                        if (!indexAssigned)
                                        {
                                            insertIndex = k;
                                            indexAssigned = true;
                                        }
                                    }
                                }
                                player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                                player.Play();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                newGame.playersList[currentPlayer].PlayerCardHand[insertIndex] = gameAdvDeck[0];
                                rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " draws " +
                                    gameAdvDeck[0].Cardname + "!\n");
                                updatePlayerHands();
                                rtbGameHistory.ScrollToCaret();
                                System.Threading.Thread.Sleep(sleepDuration - 300);
                                gameAdvDeck.RemoveAt(0);
                                countDrawnCards++;
                                secondAdvCardDrawn = true;
                                if (gameAdvDeck.Count == 0)
                                {
                                    shuffleAdventureDeck();
                                }
                                if (newGame.playersList[currentPlayer].PlayerCardHand[5].Cardname != "DummyCard")
                                {
                                    lblBannerText.Text = "Player " + newGame.playersList[currentPlayer].PlayerName +
                                    " now has 6 cards and must discard.  Please click one of the cards in your hand to discard.";
                                    btnEndTurn.Enabled = false;
                                    btnActionSubmit.Enabled = false;
                                    btnCancel.Enabled = false;
                                    btnResetTurn.Enabled = false;
                                    mustDiscard = true;
                                }
                                else
                                {
                                    SignalFloodPhase();
                                }
                            }
                        }
                        if (newGame.playersList[currentPlayer].PlayerCardHand[5].Cardname != "DummyCard")
                        {
                            lblBannerText.Text = "Player " + newGame.playersList[currentPlayer].PlayerName +
                            " now has 6 cards and must discard.  Please click one of the cards in your hand to discard.";
                            btnEndTurn.Enabled = false;
                            btnActionSubmit.Enabled = false;
                            btnCancel.Enabled = false;
                            btnResetTurn.Enabled = false;
                            mustDiscard = true;
                        }
                        setDeckLabels();
                        if (!mustDiscard)
                        {
                            btnNextPhase.Enabled = true;
                            lblBannerText.Text = "Click the continue button to proceed to flood phase.";
                            nextPhaseMode = true;
                            if (gameAdvDeck.Count == 0)
                            {
                                shuffleAdventureDeck();
                            }
                            updatePlayerHands();
                            rtbGameHistory.AppendText("****End of Player Draw Phase****\n");
                            rtbGameHistory.ScrollToCaret();
                            backgroundPlayer.PlayLooping();
                            drawPhaseCompleted = true;
                            btnResetTurn.Enabled = false;
                            secondAdvCardDrawn = false;
                        }
                    }
                    else
                    {
                        //inform player they've chosen incorrectly
                        rtbGameHistory.AppendText("You've clicked an inactive player.  Please click a card from the active player's hand to discard.");
                        rtbGameHistory.ScrollToCaret();
                    }
                }
                else
                {
                    if (currentPlayer == 3)
                    {
                        rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " discards " +
                            newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname + ".\n");
                        lblBannerText.Text = "Discard complete - proceed with game.";
                        //discard the card
                        gameAdvDiscard.Add(newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex]);
                        lblAdventureCardDiscardName.Text = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname;
                        lblAdventureCardDiscardName.ForeColor = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].CardForecolor;
                        pbAdventureDiscard.BackColor = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].CardBackground;

                        newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex] = dummyCard;
                        updatePlayerHands();
                        mustDiscard = false;
                        btnNextPhase.Enabled = true;
                        rtbGameHistory.AppendText("Click the continue button to proceed to flood phase.\n");
                        rtbGameHistory.ScrollToCaret();
                    }
                    if (secondAdvCardDrawn)
                    {
                        btnNextPhase.Enabled = true;
                        rtbGameHistory.AppendText("Click the continue button to proceed to flood phase.\n");
                        rtbGameHistory.ScrollToCaret();
                    }
                    else
                    {
                        if (gameAdvDeck[0].IswatersRise)
                        {
                            player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                            player.Play();
                            System.Threading.Thread.Sleep(sleepDuration - 300);
                            lblBannerText.Text = "<<<<----Waters Rise!---->>>>";
                            rtbGameHistory.AppendText("Waters Rise was drawn!\n");
                            rtbGameHistory.AppendText("-->Water level increases!\n");
                            rtbGameHistory.ScrollToCaret();
                            player.SoundLocation = Environment.CurrentDirectory + "\\very_scary_1.wav";
                            player.Play();
                            System.Threading.Thread.Sleep(watersRiseDuration);
                            currentWaterLevel++;
                            countDrawnCards++;
                            setWaterLevel(currentWaterLevel);
                            shufflePlaceDiscardIntoPlaces();
                            System.Threading.Thread.Sleep(sleepDuration - 300);
                            backgroundPlayer.PlayLooping();
                            pbAdventureDiscard.BackColor = gameAdvDeck[0].CardBackground;
                            lblAdventureCardDiscardName.Text = gameAdvDeck[0].Cardname;
                            rtbGameHistory.AppendText("--> Waters rise card is placed onto the adventure deck discard pile.\n");
                            rtbGameHistory.ScrollToCaret();
                            player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                            player.Play();
                            System.Threading.Thread.Sleep(sleepDuration - 300);
                            gameAdvDiscard.Add(gameAdvDeck[0]);
                            gameAdvDeck.RemoveAt(0);
                            secondAdvCardDrawn = true;
                            if (gameAdvDeck.Count == 0)
                            {
                                shuffleAdventureDeck();
                            }
                            SignalFloodPhase();
                        }
                        else
                        {
                            for (int k = 0; k <= 5; k++)
                            {
                                if (newGame.playersList[currentPlayer].PlayerCardHand[k].Cardname == "DummyCard")
                                {
                                    if (!indexAssigned)
                                    {
                                        insertIndex = k;
                                        indexAssigned = true;
                                    }
                                }
                            }
                            player.SoundLocation = Environment.CurrentDirectory + "\\carddeal.wav";
                            player.Play();
                            System.Threading.Thread.Sleep(sleepDuration - 300);
                            newGame.playersList[currentPlayer].PlayerCardHand[insertIndex] = gameAdvDeck[0];
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " draws " +
                                gameAdvDeck[0].Cardname + "!\n");
                            updatePlayerHands();
                            rtbGameHistory.ScrollToCaret();
                            System.Threading.Thread.Sleep(sleepDuration - 300);
                            gameAdvDeck.RemoveAt(0);
                            secondAdvCardDrawn = true;
                            countDrawnCards++;
                            if (gameAdvDeck.Count == 0)
                            {
                                shuffleAdventureDeck();
                            }
                            if (newGame.playersList[currentPlayer].PlayerCardHand[5].Cardname != "DummyCard")
                            {
                                lblBannerText.Text = "Player " + newGame.playersList[currentPlayer].PlayerName +
                                " now has 6 cards and must discard.  Please click one of the cards in your hand to discard.";
                                btnEndTurn.Enabled = false;
                                btnActionSubmit.Enabled = false;
                                btnCancel.Enabled = false;
                                btnResetTurn.Enabled = false;
                                mustDiscard = true;
                            }
                            else
                            {
                                SignalFloodPhase();
                            }
                        }
                    }
                    if (newGame.playersList[currentPlayer].PlayerCardHand[5].Cardname != "DummyCard")
                    {
                        lblBannerText.Text = "Player " + newGame.playersList[currentPlayer].PlayerName +
                        " now has 6 cards and must discard.  Please click one of the cards in your hand to discard.";
                        btnEndTurn.Enabled = false;
                        btnActionSubmit.Enabled = false;
                        btnCancel.Enabled = false;
                        btnResetTurn.Enabled = false;
                        mustDiscard = true;
                    }
                    setDeckLabels();
                    if (!mustDiscard)
                    {
                        btnNextPhase.Enabled = true;
                        lblBannerText.Text = "Click the continue button to proceed to flood phase.";
                        nextPhaseMode = true;
                        if (gameAdvDeck.Count == 0)
                        {
                            shuffleAdventureDeck();
                        }
                        updatePlayerHands();
                        rtbGameHistory.AppendText("****End of Player Draw Phase****\n");
                        rtbGameHistory.ScrollToCaret();
                        backgroundPlayer.PlayLooping();
                        drawPhaseCompleted = true;
                        btnResetTurn.Enabled = false;
                        secondAdvCardDrawn = false;
                        countDrawnCards = 0;
                    }
                }
            }
            //trading with player one
            else if (tradeWithEngineer)
            {
                for (int i = 0; i <= 5; i++)
                {
                    if (newGame.playersList[0].PlayerCardHand[i].Cardname == "DummyCard")
                    {
                        if (!cardTraded)
                        {
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " gave " +
                                newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname +
                                " to " + newGame.playersList[0].PlayerName + ".\n");
                            rtbGameHistory.ScrollToCaret();
                            newGame.playersList[0].PlayerCardHand[i] = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex];
                            newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex] = dummyCard;
                            updatePlayerHands();
                            cardTraded = true;
                            tradeMode = false;
                            tradeWithEngineer = false;
                            remainingMoves--;
                            lblActionsRemaining.Text = remainingMoves.ToString();
                        }
                    }
                }
                displayCurrentPhase();
            }
            //trading with player two
            else if (tradeWithNavigator)
            {
                for (int i = 0; i <= 5; i++)
                {
                    if (newGame.playersList[1].PlayerCardHand[i].Cardname == "DummyCard")
                    {
                        if (!cardTraded)
                        {
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " gave " +
                                newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname +
                                " to " + newGame.playersList[1].PlayerName + ".\n");
                            rtbGameHistory.ScrollToCaret();
                            newGame.playersList[1].PlayerCardHand[i] = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex];
                            newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex] = dummyCard;
                            updatePlayerHands();
                            cardTraded = true;
                            tradeMode = false;
                            tradeWithNavigator = false;
                            remainingMoves--;
                            lblActionsRemaining.Text = remainingMoves.ToString();
                            if (remainingMoves == 0)
                                SignalEndOfTurn();
                            else
                            {
                                lblBannerText.Text = "Trade complete - continue turn.";
                                btnActionSubmit.Enabled = true;
                                btnCancel.Enabled = false;
                                radMove.Checked = true;
                            }

                        }
                    }
                }
                displayCurrentPhase();
            }
            //trading with player three
            else if (tradeWithPilot)
            {
                for (int i = 0; i <= 5; i++)
                {
                    if (newGame.playersList[2].PlayerCardHand[i].Cardname == "DummyCard")
                    {
                        if (!cardTraded)
                        {
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " gave " +
                                newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname +
                                " to " + newGame.playersList[2].PlayerName + ".\n");
                            rtbGameHistory.ScrollToCaret();
                            newGame.playersList[2].PlayerCardHand[i] = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex];
                            newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex] = dummyCard;
                            updatePlayerHands();
                            cardTraded = true;
                            tradeMode = false;
                            tradeWithPilot = false;
                            remainingMoves--;
                            lblActionsRemaining.Text = remainingMoves.ToString();
                            if (remainingMoves == 0)
                                SignalEndOfTurn();
                            else
                            {
                                lblBannerText.Text = "Trade complete - continue turn.";
                                btnActionSubmit.Enabled = true;
                                btnCancel.Enabled = false;
                                radMove.Checked = true;
                            }

                        }
                    }
                }
                displayCurrentPhase();
            }
            //trading with player three
            else if (tradeWithExplorer)
            {
                for (int i = 0; i <= 5; i++)
                {
                    if (newGame.playersList[3].PlayerCardHand[i].Cardname == "DummyCard")
                    {
                        if (!cardTraded)
                        {
                            rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " gave " +
                                newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex].Cardname +
                                " to " + newGame.playersList[3].PlayerName + ".\n");
                            rtbGameHistory.ScrollToCaret();
                            newGame.playersList[3].PlayerCardHand[i] = newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex];
                            newGame.playersList[currentPlayer].PlayerCardHand[tradedCardIndex] = dummyCard;
                            updatePlayerHands();
                            cardTraded = true;
                            tradeMode = false;
                            tradeWithExplorer = false;
                            remainingMoves--;
                            lblActionsRemaining.Text = remainingMoves.ToString();
                            if (remainingMoves == 0)
                                SignalEndOfTurn();
                            else
                            {
                                lblBannerText.Text = "Trade complete - continue turn.";
                                btnActionSubmit.Enabled = true;
                                btnCancel.Enabled = false;
                                radMove.Checked = true;
                            }

                        }
                    }
                }
                displayCurrentPhase();
            }
            else
            {
                for (int i = 0; i <= 23; i++)
                {
                    if (currentLabel == playerHandList[i])
                    {
                        adventureCardLabelLocation = i;
                    }
                }
                if (adventureCardLabelLocation >= 0 && adventureCardLabelLocation < 6)
                    playerPlayingCard = 0;
                else if (adventureCardLabelLocation >= 6 && adventureCardLabelLocation < 12)
                    playerPlayingCard = 1;
                else if (adventureCardLabelLocation >= 12 && adventureCardLabelLocation < 18)
                    playerPlayingCard = 2;
                else if (adventureCardLabelLocation >= 18)
                    playerPlayingCard = 3;
                //check if player clicked a sandbag card
                if (playerHandList[adventureCardLabelLocation].Text == "SandBags")
                {
                    rtbGameHistory.AppendText("Sandbags: Click any flooded tile to shore it up.\n");
                    rtbGameHistory.ScrollToCaret();
                    sandbagsMode = true;
                    for (int i = 0; i <= 23; i++)
                    {
                        if (currentLabel == playerHandList[i])
                        {
                            adventureCardLabelLocation = i;
                        }
                    }
                }
                //check if player clicked a helicopter lift card
                if (playerHandList[adventureCardLabelLocation].Text == "Helicopter Lift")
                {
                    lblBannerText.Text = "Helicopter Lift: Click the tile of the player(s) you'd like to have board the helicopter.";
                    rtbGameHistory.AppendText("Helicopter Lift: Click the tile of the player(s) you'd like to have board the helicopter.\n");
                    rtbGameHistory.ScrollToCaret();
                    helicopterMode = true;
                    liftFirstTileSelected = false;
                    liftConfirmed = false;
                    liftSecondTileSelected = false;
                    for (int i = 0; i <= 23; i++)
                    {
                        if (currentLabel == playerHandList[i])
                        {
                            adventureCardLabelLocation = i;
                        }
                    }
                }
            }
        }
        #endregion

        #region mouse enter handlers
        private void PictureBoxMouseEnterHandler(System.Object sender, System.EventArgs e)
        {
            PictureBox currentPB = (PictureBox)sender;
            int currentPBLocation=-1;
            //set current picture box location
            for (int i = 0; i <= 23; i++)
            {
                if (currentPB == tilePanelList[i].forePanel.Controls[1] ||
                    currentPB == tilePanelList[i].forePanel.Controls[2] ||
                    currentPB == tilePanelList[i].forePanel.Controls[3] ||
                    currentPB == tilePanelList[i].forePanel.Controls[4])
                {
                    currentPBLocation = i;
                }
            }

            if (moveMode)
            {
                for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                {
                    if (currentValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[currentPlayer].CurrentLocation)
                        tilePanelList[currentPBLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                            newGame.playersList[currentPlayer].PlayerTransImage;
                }
            }
            else if (explorerMoveMode)
            {
                for (int j = 0; j <= explorerValidMoves.Count() - 1; j++)
                {
                    if (explorerValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[currentPlayer].CurrentLocation)
                        tilePanelList[currentPBLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                            newGame.playersList[currentPlayer].PlayerTransImage;
                }
            }
            else if (specialMode)
            {
                if (specialPlayer == "Pilot" && newGame.playersList[2].CurrentLocation != currentPBLocation)
                {
                    tilePanelList[currentPBLocation].forePanel.Controls[3].BackgroundImage =
                        newGame.playersList[currentPlayer].PlayerTransImage;
                }
                else if (specialPlayer == "Navigator" && playerIndexClicked != -1 && playerTokenClicked)
                {
                    resetNavValidMoves();
                    navValidMoves = findCurrentValidMoves(newGame.playersList[playerIndexClicked].CurrentLocation);
                    for (int j = 0; j <= navValidMoves.Count() - 1; j++)
                    {
                        if (navValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[playerIndexClicked].CurrentLocation)
                            tilePanelList[currentPBLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage =
                                newGame.playersList[playerIndexClicked].PlayerTransImage;
                    }
                }
            }
        }
        private void MouseEnterHandler(System.Object sender, System.EventArgs e)
        {
            Panel currentPanel = (Panel)sender;
            int currentPanelLocation=-1;

            //set current panel location
            for (int i = 0; i <= 23; i++)
            {
                if (currentPanel == tilePanelList[i].forePanel)
                {
                    currentPanelLocation = i;
                }
            }
            if (moveMode)
            {
                for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                {
                    if (currentValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[currentPlayer].CurrentLocation)
                        tilePanelList[currentPanelLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                            newGame.playersList[currentPlayer].PlayerTransImage;
                }
            }
            else if (explorerMoveMode)
            {
                for (int j = 0; j <= explorerValidMoves.Count() - 1; j++)
                {
                    if (explorerValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[currentPlayer].CurrentLocation)
                        tilePanelList[currentPanelLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage =
                            newGame.playersList[currentPlayer].PlayerTransImage;
                }
            }
            else if (specialMode)
            {
                if (specialPlayer == "Pilot" && newGame.playersList[2].CurrentLocation != currentPanelLocation)
                {
                    tilePanelList[currentPanelLocation].forePanel.Controls[3].BackgroundImage =
                        newGame.playersList[currentPlayer].PlayerTransImage;
                }
                else if (specialPlayer == "Navigator" && playerIndexClicked != -1 && playerTokenClicked)
                {
                    resetNavValidMoves();
                    navValidMoves = findCurrentValidMoves(newGame.playersList[playerIndexClicked].CurrentLocation);
                    for (int j = 0; j <= navValidMoves.Count() - 1; j++)
                    {
                        if (navValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[playerIndexClicked].CurrentLocation)
                            tilePanelList[currentPanelLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage =
                                newGame.playersList[playerIndexClicked].PlayerTransImage;
                    }
                }
            }
        }
        
        #endregion
        private void MouseOutHandler(System.Object sender, System.EventArgs e)
        {
            Panel currentPanel = (Panel)sender;
            int currentPanelLocation = -1;
            
            //find current panel location
            for (int i = 0; i <= 23; i++)
            {
                if (currentPanel == tilePanelList[i].forePanel)
                {
                    currentPanelLocation = i;
                }
            }
            if (moveMode)
            {
                for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                {
                    if (currentValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[currentPlayer].CurrentLocation)
                        tilePanelList[currentPanelLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                }
            }
            else if (explorerMoveMode)
            {
                for (int j = 0; j <= explorerValidMoves.Count() - 1; j++)
                {
                    if (explorerValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[currentPlayer].CurrentLocation)
                        tilePanelList[currentPanelLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                }
            }
            else if (specialMode)
            {
                if (specialPlayer == "Pilot" && newGame.playersList[2].CurrentLocation != currentPanelLocation)
                {
                    tilePanelList[currentPanelLocation].forePanel.Controls[3].BackgroundImage = null;
                }
                else if (specialPlayer == "Navigator" && playerIndexClicked != -1 && playerTokenClicked)
                {
                    resetNavValidMoves();
                    navValidMoves = findCurrentValidMoves(newGame.playersList[playerIndexClicked].CurrentLocation);
                    for (int j = 0; j <= navValidMoves.Count() - 1; j++)
                    {
                        if (navValidMoves[j] == currentPanelLocation && currentPanelLocation != newGame.playersList[playerIndexClicked].CurrentLocation)
                            tilePanelList[currentPanelLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage =
                                null;
                    }
                }
            }
        }

        private void PictureBoxMouseOutHandler(System.Object sender, System.EventArgs e)
        {
            PictureBox currentPB = (PictureBox)sender;
            int currentPBLocation = -1;
            //set current picture box location
            for (int i = 0; i <= 23; i++)
            {
                if (currentPB == tilePanelList[i].forePanel.Controls[1] ||
                    currentPB == tilePanelList[i].forePanel.Controls[2] ||
                    currentPB == tilePanelList[i].forePanel.Controls[3] ||
                    currentPB == tilePanelList[i].forePanel.Controls[4])
                {
                    currentPBLocation = i;
                }
            }
            if (moveMode)
            {
                for (int j = 0; j <= currentValidMoves.Count() - 1; j++)
                {
                    if (currentValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[currentPlayer].CurrentLocation)
                        tilePanelList[currentPBLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                }
            }
            else if (explorerMoveMode)
            {
                for (int j = 0; j <= explorerValidMoves.Count() - 1; j++)
                {
                    if (explorerValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[currentPlayer].CurrentLocation)
                        tilePanelList[currentPBLocation].forePanel.Controls[currentPlayer + 1].BackgroundImage = null;
                }
            }
            else if (specialMode)
            {
                if (specialPlayer == "Pilot" && newGame.playersList[2].CurrentLocation != currentPBLocation)
                {
                    tilePanelList[currentPBLocation].forePanel.Controls[3].BackgroundImage = null;
                }
                else if (specialPlayer == "Navigator" && playerIndexClicked != -1 && playerTokenClicked)
                {
                    resetNavValidMoves();
                    navValidMoves = findCurrentValidMoves(newGame.playersList[playerIndexClicked].CurrentLocation);
                    for (int j = 0; j <= navValidMoves.Count() - 1; j++)
                    {
                        if (navValidMoves[j] == currentPBLocation && currentPBLocation != newGame.playersList[playerIndexClicked].CurrentLocation)
                            tilePanelList[currentPBLocation].forePanel.Controls[playerIndexClicked + 1].BackgroundImage =
                                newGame.playersList[playerIndexClicked].PlayerTransImage;
                    }
                }
            }
        }

        void adventureCard_MouseOut(object sender, EventArgs e)
        {
            Label thisLabel = (Label)sender;
            int currentLabel = -1;
            int currentPlayer = -1;
            int cardNumber = -1;
            string toolTipText;

            for (int i = 0; i <= 23; i++)
            {
                if (thisLabel == playerHandList[i])
                {
                    currentLabel = i;
                    if (currentLabel <= 5)
                    {
                        currentPlayer = 0;
                        cardNumber = currentLabel;
                    }

                    else if (currentLabel <= 11)
                    {
                        currentPlayer = 1;
                        cardNumber = currentLabel - 6;

                    }
                    else if (currentLabel <= 17)
                    {
                        currentPlayer = 2;
                        cardNumber = currentLabel - 12;
                    }
                    else
                    {
                        currentPlayer = 3;
                        cardNumber = currentLabel - 18;
                    }

                }
            }
            adventureCardTooltip.AutomaticDelay = 0;
            adventureCardTooltip.UseFading = true;
            if (newGame.playersList[currentPlayer].PlayerCardHand[cardNumber].FullCardText != null)
            {
                toolTipText = newGame.playersList[currentPlayer].PlayerCardHand[cardNumber].FullCardText;
                this.adventureCardTooltip.Hide(thisLabel);
            }
        }

        void adventureCard_MouseEnter(object sender, EventArgs e)
        {
            Label thisLabel = (Label)sender;
            int currentLabel = -1;
            int currentPlayer = -1;
            int cardNumber = -1;
            string toolTipText;

            for (int i = 0; i <= 23; i++)
            {
                if (thisLabel == playerHandList[i])
                {
                    currentLabel = i;
                    if (currentLabel <= 5)
                    {
                        currentPlayer = 0;
                        cardNumber = currentLabel;
                    }

                    else if (currentLabel <= 11)
                    {
                        currentPlayer = 1;
                        cardNumber = currentLabel - 6;

                    }
                    else if (currentLabel <= 17)
                    {
                        currentPlayer = 2;
                        cardNumber = currentLabel - 12;
                    }
                    else
                    {
                        currentPlayer = 3;
                        cardNumber = currentLabel - 18;
                    }
                }
            }
            adventureCardTooltip.AutomaticDelay = 0;
            adventureCardTooltip.UseFading = true;
            if (newGame.playersList[currentPlayer].PlayerCardHand[cardNumber].FullCardText != null)
            {
                toolTipText = newGame.playersList[currentPlayer].PlayerCardHand[cardNumber].FullCardText;
                this.adventureCardTooltip.Show(toolTipText, thisLabel, new Point(40, -20));
            }
        }

        #region action button and cancel button
        private void btnActionSubmit_Click(object sender, EventArgs e)
        {
            btnActionSubmit.Enabled = false;
            btnCancel.Enabled = true;
            btnEndTurn.Enabled = false;
            btnResetTurn.Enabled = false;

            int currentPlayerLocation = newGame.playersList[currentPlayer].CurrentLocation;
            validShoreTiles = 0;
            if (radMove.Checked)
            {
                if (currentPlayer == 3)
                {
                    explorerMoveMode = true;
                    lblBannerText.Text = "Click the tile where you'd like to move.";
                    explorerValidMoves = findExplorerValidMoves(currentPlayerLocation);
                }
                else
                {
                    moveMode = true;
                    lblBannerText.Text = "Click the tile where you'd like to move.";
                    resetCurrentValidMoves();
                    currentValidMoves = findCurrentValidMoves(currentPlayerLocation);
                }
            }
            else if (radShore.Checked)
            {
                if (currentPlayer == 3)
                {
                    explorerShoreUpMode = true;
                    lblBannerText.Text = "Click the tile you'd like to shore up.  Must be adjacent or diagonal to your location, or your current location.";
                    explorerValidMoves = findExplorerValidMoves(currentPlayerLocation);
                }
                else
                {
                    shoreUpMode = true;
                    lblBannerText.Text = "Click the tile you'd like to shore up.  Must be adjacent to your location, or your current location.";
                    resetCurrentValidMoves();
                    currentValidMoves = findCurrentValidMoves(currentPlayerLocation);
                }
            }
            else if (radTrade.Checked)
            {
                tradeMode = true;
                tileTradeLocation = newGame.playersList[currentPlayer].CurrentLocation;
                lblBannerText.Text = "Click on the token of the player with whom you'd like to trade.";
            }
            else if (radSpecial.Checked)
            {
                specialMode = true;
                //engineer
                if (currentPlayer == 0)
                {
                    for (int i = 0; i <= 4; i++)
                    {
                        engineerShoreTiles[i] = -1;
                    }
                    resetCurrentValidMoves();
                    currentValidMoves = findCurrentValidMoves(currentPlayerLocation);

                    for (int i = 0; i <= currentValidMoves.Count() - 1; i++)
                    {
                        engineerShoreTiles[i] = currentValidMoves[i];
                    }
                    if (engineerShoreTiles.Count() <= 4)
                        engineerShoreTiles[engineerShoreTiles.Count()] = currentPlayerLocation;
                    else
                        engineerShoreTiles[4] = currentPlayerLocation;
                    for (int i = 0; i <= engineerShoreTiles.Count()-1; i++)
                    {
                        if (gameTiles[engineerShoreTiles[i]].wStatus == "Flooded")
                        {
                            validShoreTiles++;
                        }
                    }
                    if (validShoreTiles <= 1)
                    {
                        lblBannerText.Text = "Engineer must be adjacent to two flooded tiles - action cancelled.  Please select another action.";
                        specialMode = false;
                        btnActionSubmit.Enabled = true;
                        btnCancel.Enabled = false;
                        radMove.Checked = true;
                    }
                    else
                    {
                        specialPlayer = "Engineer";
                        lblBannerText.Text = "Engineer special action: Please click the first tile you'd like to shore up.";
                        shoredTiles = 0;
                    }
                }                
                //navigator
                else if (currentPlayer == 1)
                {
                    specialPlayer = "Navigator";
                    lblBannerText.Text = "Navigator special action: Please click the token of the player you'd like to move.";
                    playerTokenClicked = false;
                    navMode = true;
                }

                //pilot
                else if (currentPlayer == 2)
                {
                    if (!pilotSpecialUsed)
                    {
                        specialPlayer = "Pilot";
                        lblBannerText.Text = "Pilot special action: Click on the tile where you'd like to move.";
                    }
                    else
                    {
                        lblBannerText.Text = "Pilot special has already been used this turn - action cancelled.  Please select another action.";
                        btnActionSubmit.Enabled = true;
                        btnCancel.Enabled = false;
                        specialMode = false;
                    }
                }
                //explorer
                else if (currentPlayer == 3)
                    specialPlayer = "Explorer";                    
            }
            else if (radClaim.Checked)
            {
                int treasureCardRemoved = 0;
                if (gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Temple of Luna" ||
                    gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Temple of Ra")
                {
                    lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " claims the Earth Statue!";
                    rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " claims the Earth Statue!\n");
                    rtbGameHistory.ScrollToCaret();
                    pbUnclaimedStatue.Visible = false;
                    lblUnclaimedStatue.Visible = false;
                    pbClaimedStatue.Visible = true;
                    lblClaimedStatue.Visible = true;
                    statueClaimed = true;
                    for (int i = 0; i <= 4; i++)
                    {
                        if (newGame.playersList[currentPlayer].PlayerCardHand[i].Cardname == "Earth Statue" && treasureCardRemoved < 4)
                        {
                            newGame.playersList[currentPlayer].PlayerCardHand[i] = dummyCard;
                            treasureCardRemoved++;
                        }
                    }
                }
                else if (gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Garden of Lupus" ||
                    gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Garden of Disquiet")
                {
                    lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " claims the Wind Carving!";
                    rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " claims the Wind Carving!\n");
                    rtbGameHistory.ScrollToCaret();
                    pbUnclaimedSphinx.Visible = false;
                    lblUnclaimedSphinx.Visible = false;
                    pbClaimedSphinx.Visible = true;
                    lblClaimedSphinx.Visible = true;
                    carvingClaimed = true;
                    for (int i = 0; i <= 4; i++)
                    {
                        if (newGame.playersList[currentPlayer].PlayerCardHand[i].Cardname == "Wind Carving" && treasureCardRemoved < 4)
                        {
                            newGame.playersList[currentPlayer].PlayerCardHand[i] = dummyCard;
                            treasureCardRemoved++;
                        }
                    }
                    updatePlayerHands();
                }
                else if (gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Cultist's Cave" ||
                    gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Reptile's Cave")
                {
                    lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " claims the Fire Totem!";
                    rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " claims the Fire Totem!\n");
                    rtbGameHistory.ScrollToCaret();
                    pbUnclaimedDragon.Visible = false;
                    lblUnclaimedDragon.Visible = false;
                    pbClaimedDragon.Visible = true;
                    lblClaimedDragon.Visible = true;
                    totemClaimed = true;
                    for (int i = 0; i <= 4; i++)
                    {
                        if (newGame.playersList[currentPlayer].PlayerCardHand[i].Cardname == "Fire Totem" && treasureCardRemoved < 4)
                        {
                            newGame.playersList[currentPlayer].PlayerCardHand[i] = dummyCard;
                            treasureCardRemoved++;
                        }
                    }
                    updatePlayerHands();
                }
                else if (gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Serpent Palace" ||
                    gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Sea King's Palace")
                {
                    lblBannerText.Text = newGame.playersList[currentPlayer].PlayerName + " claims the Water Chalice!";
                    rtbGameHistory.AppendText(newGame.playersList[currentPlayer].PlayerName + " claims the Water Chalice!\n");
                    rtbGameHistory.ScrollToCaret();
                    pbUnclaimedChalice.Visible = false;
                    lblUnclaimedChalice.Visible = false;
                    pbClaimedChalice.Visible = true;
                    lblClaimedChalice.Visible = true;
                    chaliceClaimed = true;
                    for (int i = 0; i <= 4; i++)
                    {
                        if (newGame.playersList[currentPlayer].PlayerCardHand[i].Cardname == "Water Chalice" && treasureCardRemoved < 4)
                        {
                            newGame.playersList[currentPlayer].PlayerCardHand[i] = dummyCard;
                            treasureCardRemoved++;
                        }
                    }
                    updatePlayerHands();
                }
                radClaim.Enabled = false;
                player.SoundLocation = Environment.CurrentDirectory + "\\Treasure_Claim.wav";
                player.Play();
                System.Threading.Thread.Sleep(sleepDuration*3);
                backgroundPlayer.PlayLooping();
                displayCurrentPhase();
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            btnActionSubmit.Enabled = true;
            btnCancel.Enabled = false;
            if (moveMode)
            {
                moveMode = false;
                lblBannerText.Text = "Movement mode cancelled.";
                lblBannerText.Focus();
            }
            else if (shoreUpMode)
            {
                shoreUpMode = false;
                lblBannerText.Text = "Shore up mode cancelled.";
            }
            else if (tradeMode)
            {
                tradeMode = false;
                lblBannerText.Text = "Trade mode cancelled.";
            }
            else if (specialMode)
            {
                specialMode = false;
                lblBannerText.Text = "Special mode cancelled.";

            }
        }
        #endregion
        private void takeAction()
        {
            remainingMoves--;
            lblActionsRemaining.Text = remainingMoves.ToString();
            refreshPlayerTokens();
        }
        private void SignalEndOfTurn()
        {
            lblBannerText.Text = "0 Actions Remaining - click \"End Turn\" or \"Reset Turn button\".";
            btnActionSubmit.Enabled = false;
            btnCancel.Enabled = false;
        }
        private void SignalFloodPhase()
        {
            lblBannerText.Text = "Click the continue button to proceed to flood phase.";
            btnEndTurn.Enabled = false;
            btnResetTurn.Enabled = false;
            btnActionSubmit.Enabled = false;
            btnCancel.Enabled = false;
        }
       
        private void btnEndTurn_Click(object sender, EventArgs e)
        {
            checkWinLoss();
            DialogResult dr = new DialogResult();
            if (!gameOver)
            {
                if (remainingMoves > 0)
                {
                    dr = MessageBox.Show("You still have actions remaining!  Are you sure you want to end your turn?", "End Turn Confirmation", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Yes)
                    {
                        lblBannerText.Focus();
                        btnEndTurn.Enabled = false;
                        doAdventureCardsPhase();
                        refreshPlayerTokens();
                        pilotSpecialUsed = false;
                    }
                    else
                    {
                        //null, since no just returns you to the game
                    }
                }
                else
                {
                    lblBannerText.Focus();
                    btnEndTurn.Enabled = false;
                    doAdventureCardsPhase();
                    refreshPlayerTokens();
                    pilotSpecialUsed = false;
                }
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            updatePlayerHands();
        }

        private void btnNextPhase_Click(object sender, EventArgs e)
        {
            if (!navMode)
            {
                updatePlayerHands();
                doFloodPhase();
                GetNextPlayer();
                backgroundPlayer.PlayLooping();
                btnNextPhase.Enabled = false;
                radMove.Checked = true;
                radMove.Focus();
                pilotSpecialUsed = false;
            }
            else
            {
                takeAction();
                navMode = false;
                navFirstMove = false;
                specialMode = false;

                playerTokenClicked = false;
                checkResetTurn();
                displayCurrentPhase();
            }
        }
        //shuffle adventure discard into adventure deck
        private void shuffleAdventureDeck()
        {
            gameAdvDiscard.ShuffleInPlace();
            int adventureDeckDiscardCount = gameAdvDiscard.Count();

            for (int i = 0; i <= gameAdvDiscard.Count()-1; i++)
            {
                gameAdvDeck.Add(gameAdvDiscard[i]);
            }
            for (int l = 0; l <= adventureDeckDiscardCount-1; l++)
            {
                if(gameAdvDiscard.Count!=0)
                    gameAdvDiscard.RemoveAt(0);
            }
            setDeckLabels();
            lblAdventureCardDiscardName.Text = "(Empty)";
            lblAdventureCardDiscardName.BackColor = Color.Black;
            pbAdventureDiscard.BackColor = Color.Black;
            rtbGameHistory.AppendText("Last adventure deck card drawn - shuffling discard pile and replacing adventure deck.\n");
            rtbGameHistory.ScrollToCaret();
            player.SoundLocation = Environment.CurrentDirectory + "\\shuffle.wav";
            player.Play();
            System.Threading.Thread.Sleep(600);
            backgroundPlayer.PlayLooping();
        }
        //refresh player tokens in case there's some kind of tile hover error
        private void refreshPlayerTokens()
        {
            for (int i = 0; i <= 23; i++)
            {
                for (int j = 0; j <= 3; j++)
                {
                    if (newGame.playersList[j].CurrentLocation != i)
                    {
                        tilePanelList[i].forePanel.Controls[j + 1].BackgroundImage = null;
                    }
                    else
                    {
                        tilePanelList[i].forePanel.Controls[j + 1].BackgroundImage = newGame.playersList[j].PlayerToken;
                    }
                }
            }
        }

        private void resetCurrentValidMoves()
        {
            for (int i = 0; i <= 3; i++)
            {
                currentValidMoves[i] = -1;
            }
        }
        private void resetNavValidMoves()
        {
            for (int i = 0; i <= navValidMoves.Count() - 1; i++)
            {
                navValidMoves[i] = -1;
            }
        }
        private int[] findCurrentValidMoves(int locationIndex)
        {
            int [] validMoveSet = new int [4];
            for (int i = 0; i <= 3; i++)
            {
                if (newGame.ValidMoves[locationIndex,i] != -1)
                    validMoveSet[i] = newGame.ValidMoves[locationIndex, i];
            }
            return validMoveSet;
        }

        private int[] findExplorerValidMoves(int locationIndex)
        {
            int [] tempValidMoveSet = new int[8];
            int [] combinedValidMoveSet = new int [8];
            int count = 0;
            int tempMovesCount = 0;
            for (int i = 0; i <= 3; i++)
            {
                tempValidMoveSet[i] = newGame.ValidMoves[locationIndex, i];
            }
            for (int j = 4; j <= 7; j++)
            {
                tempValidMoveSet[j] = newGame.ExplorerValidMoves[locationIndex, tempMovesCount];
                tempMovesCount++;
            }
            for (int k = 0; k <= 7; k++)
            {
                if (tempValidMoveSet[k] != -1)
                {
                    combinedValidMoveSet[count] = tempValidMoveSet[k];
                    count++;
                }
            }
            return combinedValidMoveSet;
        }

        //determines whether current player may claim treasure, and toggles claim radio button
        private void checkTreasureClaim()
        {
            string claimType = "";
            int statueCount = 0;
            int carvingCount = 0;
            int totemCount = 0;
            int chaliceCount = 0;

            //is current player tile a special tile?
            if (!gameTiles[newGame.playersList[currentPlayer].CurrentLocation].spec)
            {
                radClaim.Enabled = false;
            }
            else
            {
                //which special tile?
                if (gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Temple of Luna" 
                    || gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Temple of Ra")
                {
                    claimType = "Statue";
                }
                else if (gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Garden of Lupus"
                    || gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Garden of Disquiet")
                {
                    claimType = "Carving";
                }
                else if (gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Cultist's Cave"
                    || gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Reptile's Cave")
                {
                    claimType = "Totem";
                }
                else if (gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Serpent Palace"
                    || gameTiles[newGame.playersList[currentPlayer].CurrentLocation].Name == "Sea King's Palace")
                {
                    claimType = "Chalice";
                }
                //does player have four special cards in his hand?
                for (int i = 0; i <= 4; i++)
                {
                    if (newGame.playersList[currentPlayer].PlayerCardHand[i].IsTreasure)
                    {
                        if (newGame.playersList[currentPlayer].PlayerCardHand[i].Cardname == "Earth Statue")
                            statueCount++;
                        else if (newGame.playersList[currentPlayer].PlayerCardHand[i].Cardname == "Wind Carving")
                            carvingCount++;
                        else if (newGame.playersList[currentPlayer].PlayerCardHand[i].Cardname == "Fire Totem")
                            totemCount++;
                        else if (newGame.playersList[currentPlayer].PlayerCardHand[i].Cardname == "Water Chalice")
                            chaliceCount++;
                    }
                }
                //enable claim radio button if player is on correct tile and has the correct cards in hand
                if (statueCount >= 4 && claimType == "Statue")
                    radClaim.Enabled = true;
                else if (carvingCount >= 4 && claimType == "Carving")
                    radClaim.Enabled = true;
                else if (totemCount >= 4 && claimType == "Totem")
                    radClaim.Enabled = true;
                else if (chaliceCount >= 4 && claimType == "Chalice")
                    radClaim.Enabled = true;
                else
                    radClaim.Enabled = false;
            }

        }

        private void btnShuffleTest_Click(object sender, EventArgs e)
        {
            shuffleAdventureDeck();
        }

        private void btnLift_Click(object sender, EventArgs e)
        {
            HelicopterLift hl = new HelicopterLift(this);
            hl.setActivePlayers(1, 1, 0, 1);
            hl.Show();
            hl.Activate();
        }

        //public property used by HelicopterLift form to set which players are on the lift
        public void setLiftPlayers(bool p1, bool p2, bool p3, bool p4)
        {
            liftPlayerOne = p1;
            liftPlayerTwo = p2;
            liftPlayerThree = p3;
            liftPlayerFour = p4;
        }

        //sets whether helicopter lift flight was confirmed or cancelled
        public void setLiftStatus(bool status)
        {
            liftConfirmed = status;
        }

        public void setBannerText(string text)
        {
            lblBannerText.Text = text;
        }

        public void appendGameHistoryText(string text)
        {
            rtbGameHistory.AppendText(text + "\n");
            rtbGameHistory.ScrollToCaret();
        }

        public void checkWinLoss()
        {
            //check loss conditions

            //1. Freedom's Landing sinks
            if (gameTiles[findPlaceTile("Freedom's Landing")].wStatus == "Sunk")
            {
                lblBannerText.Text = "Freedom's Landing has sunk!  GAME OVER!";
                rtbGameHistory.AppendText("Freedom's Landing has sunk!  GAME OVER!\n");
                rtbGameHistory.ScrollToCaret();
                doGameOver();
            }
            //2. Two treasure claim tiles of an unclaimed treasure sink
            if (gameTiles[findPlaceTile("Temple of Luna")].wStatus == "Sunk" &&
                gameTiles[findPlaceTile("Temple of Ra")].wStatus == "Sunk" &&
                (!statueClaimed))
            {
                lblBannerText.Text = "Both earth statue claim tiles have sunk, and you've not claimed the earth statue.  GAME OVER!";
                rtbGameHistory.AppendText("Both earth statue claim tiles have sunk, and you've not claimed the earth statue.  GAME OVER!\n");
                rtbGameHistory.ScrollToCaret();
                doGameOver();
            }
            if (gameTiles[findPlaceTile("Garden of Lupus")].wStatus == "Sunk" &&
                gameTiles[findPlaceTile("Garden of Disquiet")].wStatus == "Sunk" &&
                (!carvingClaimed))
            {
                lblBannerText.Text = "Both wind carving claim tiles have sunk, and you've not claimed the wind carving.  GAME OVER!";
                rtbGameHistory.AppendText("Both wind carving claim tiles have sunk, and you've not claimed the wind carving.  GAME OVER!\n");
                rtbGameHistory.ScrollToCaret();
                doGameOver();
            }
            if (gameTiles[findPlaceTile("Cultist's Cave")].wStatus == "Sunk" &&
                gameTiles[findPlaceTile("Reptile's Cave")].wStatus == "Sunk" &&
                (!totemClaimed))
            {
                lblBannerText.Text = "Both fire totem claim tiles have sunk, and you've not claimed the fire totem.  GAME OVER!";
                rtbGameHistory.AppendText("Both fire totem claim tiles have sunk, and you've not claimed the fire totem.  GAME OVER!\n");
                rtbGameHistory.ScrollToCaret();
                doGameOver();
            }
            if (gameTiles[findPlaceTile("Serpent Palace")].wStatus == "Sunk" &&
                gameTiles[findPlaceTile("Sea King's Palace")].wStatus == "Sunk" &&
                (!chaliceClaimed))
            {
                lblBannerText.Text = "Both water chalice claim tiles have sunk, and you've not claimed the water chalice.  GAME OVER!";
                rtbGameHistory.AppendText("Both water chalice claim tiles have sunk, and you've not claimed the water chalice.  GAME OVER!\n");
                rtbGameHistory.ScrollToCaret();
                doGameOver();
            }
            //3. Water level reached skull and crossbones
            if (currentWaterLevel == 10)
            {
                lblBannerText.Text = "The entire island has flooded due to reaching water level 10.  GAME OVER!";
                rtbGameHistory.AppendText("The entire island has flooded due to reaching water level 10.  GAME OVER!");
                rtbGameHistory.ScrollToCaret();
                doGameOver();
            }
            //check win condition - all four treasures claimed, all four players are on Freedom's Landing, and at least one player has a helicopter lift
            if (statueClaimed && totemClaimed && chaliceClaimed && carvingClaimed &&
                (findPlaceTile("Freedom's Landing") == newGame.playersList[0].CurrentLocation) &&
                (findPlaceTile("Freedom's Landing") == newGame.playersList[1].CurrentLocation) &&
                (findPlaceTile("Freedom's Landing") == newGame.playersList[2].CurrentLocation) &&
                (findPlaceTile("Freedom's Landing") == newGame.playersList[3].CurrentLocation) &&
                playersHaveLift())
            {
                lblBannerText.Text = "The players have escaped the island with all treasures.  YOU WIN!";
                rtbGameHistory.AppendText("The players have escaped the island with all treasures.  YOU WIN!");
                rtbGameHistory.ScrollToCaret();
                playersWin();
                gameOver = true;
            }
        }

        public void doGameOver()
        {
            gameOver = true;
            btnEndTurn.Enabled = false;
            btnResetTurn.Enabled = false;
            btnNextPhase.Enabled = false;
            btnActionSubmit.Enabled = false;
            btnCancel.Enabled = false;
            player.SoundLocation = Environment.CurrentDirectory + "\\dundundun.wav";
            player.Play();
            System.Threading.Thread.Sleep(sleepDuration+1000);
            player.SoundLocation = Environment.CurrentDirectory + "\\aliens_gameover.wav";
            player.Play();
            System.Threading.Thread.Sleep(sleepDuration+2000);
            player.SoundLocation = Environment.CurrentDirectory + "\\opium.wav";
            player.Play();
            btnEndTurn.Enabled = false;
            btnResetTurn.Enabled = false;
            btnNextPhase.Enabled = false;
            btnActionSubmit.Enabled = false;
            btnCancel.Enabled = false;

        }

        public void playersWin()
        {
            gameOver = true;
            btnEndTurn.Enabled = false;
            btnResetTurn.Enabled = false;
            btnNextPhase.Enabled = false;
            btnActionSubmit.Enabled = false;
            btnCancel.Enabled = false;
            player.SoundLocation = Environment.CurrentDirectory + "\\gamewon.wav";
            player.Play();
            System.Threading.Thread.Sleep(sleepDuration + 200);
            player.SoundLocation = Environment.CurrentDirectory + "\\island_fever.wav";
            player.Play();
            btnEndTurn.Enabled = false;
            btnResetTurn.Enabled = false;
            btnNextPhase.Enabled = false;
            btnActionSubmit.Enabled = false;
            btnCancel.Enabled = false;
        }

        public bool playersHaveLift()
        {
            for (int i = 0; i <= 3; i++)
            {
                for (int j = 0; j <= 5; j++)
                {
                    if (newGame.playersList[i].PlayerCardHand[j].Cardname == "Helicopter Lift")
                        return true;
                }
            }
            return false;
        }

        private void btnGameOver_Click(object sender, EventArgs e)
        {
            doGameOver();
        }

        private void btnWin_Click(object sender, EventArgs e)
        {
            playersWin();
        }

        private void displayCurrentPhase()
        {
            if (remainingMoves == 0)
            {
                if (!drawPhaseCompleted)
                {
                    SignalEndOfTurn();
                    btnEndTurn.Enabled = true;
                    checkResetTurn();
                }
                else
                {
                    SignalFloodPhase();
                }
            }
            else
            {
                btnActionSubmit.Enabled = true;
                btnCancel.Enabled = false;
                btnEndTurn.Enabled = true;
                checkResetTurn();
                btnNextPhase.Enabled = false;
                lblBannerText.Text = "Action complete, " + remainingMoves.ToString() + " actions remaining - continue turn.";
            }
            lblBannerText.Focus();
        }

        #region menu strip items
        private void objectOfTheGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ObjectOfGame oog = new ObjectOfGame();
            oog.StartPosition = FormStartPosition.Manual;
            oog.Location = new Point(213, 213);
            oog.Activate();
            oog.Visible = true;
        }

        private void orderOfPlayToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OrderOfPlay oop = new OrderOfPlay();
            oop.StartPosition = FormStartPosition.Manual;
            oop.Location = new Point(213, 213);
            oop.Activate();
            oop.Visible = true;
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            Taking_Actions ta = new Taking_Actions();
            ta.StartPosition = FormStartPosition.Manual;
            ta.Location = new Point(213, 213);
            ta.Activate();
            ta.Visible = true;
        }

        private void exitToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void losingTheGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LossConditions lc = new LossConditions();
            lc.StartPosition = FormStartPosition.Manual;
            lc.Location = new Point(213, 213);
            lc.Activate();
            lc.Visible = true;
        }

        private void winningTheGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Winning win = new Winning();
            win.StartPosition = FormStartPosition.Manual;
            win.Location = new Point(213, 213);
            win.Activate();
            win.Visible = true;
        }

        #endregion

        private void setDeckLabels()
        {
            lblPlacesDeckCount.Text = placeCardDeck.Count().ToString();
            lblPlacesDiscardCount.Text = placeCardDiscard.Count().ToString();
            lblAdventureDeckCount.Text = gameAdvDeck.Count().ToString();
            lblAdventureDeckDiscardCount.Text = gameAdvDiscard.Count().ToString();
        }

        private void discardUsedAdventureCard(int cardLocation)
        {
            if (playerPlayingCard == 0)
            {
                gameAdvDiscard.Add(newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation]);
                lblAdventureCardDiscardName.Text = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation].Cardname;
                lblAdventureCardDiscardName.ForeColor = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation].CardForecolor;
                pbAdventureDiscard.BackColor = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation].CardBackground;
            }
            else if (playerPlayingCard == 1)
            {
                gameAdvDiscard.Add(newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-6]);
                lblAdventureCardDiscardName.Text = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-6].Cardname;
                lblAdventureCardDiscardName.ForeColor = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-6].CardForecolor;
                pbAdventureDiscard.BackColor = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-6].CardBackground;
            }
            else if (playerPlayingCard == 2)
            {
                gameAdvDiscard.Add(newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-12]);
                lblAdventureCardDiscardName.Text = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-12].Cardname;
                lblAdventureCardDiscardName.ForeColor = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-12].CardForecolor;
                pbAdventureDiscard.BackColor = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-12].CardBackground;
            }
            else if (playerPlayingCard == 3)
            {
                gameAdvDiscard.Add(newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-18]);
                lblAdventureCardDiscardName.Text = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-18].Cardname;
                lblAdventureCardDiscardName.ForeColor = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-18].CardForecolor;
                pbAdventureDiscard.BackColor = newGame.playersList[playerPlayingCard].PlayerCardHand[cardLocation-18].CardBackground;
            }
        }

        private void resetAllVariables()
        {
            btnActionSubmit.Enabled = true;
            btnCancel.Enabled = false;
            btnEndTurn.Enabled = true;
            checkResetTurn();
            moveMode = false;
            explorerShoreUpMode = false;
            shoreUpMode = false;
            tradeMode = false;
            specialMode = false;
            resetCurrentValidMoves();
            for (int i = 0; i <= 4; i++)
            {
                engineerShoreTiles[i] = -1;
            }
            specialPlayer = "";
            shoredTiles = 0;
            playerTokenClicked = false;
            navMode = false;
            statueClaimed = false;
            chaliceClaimed = false;
            totemClaimed = false;
            carvingClaimed = false;
            liftPlayerOne = false;
            liftPlayerTwo = false;
            liftPlayerThree = false;
            liftPlayerFour = false;
            liftFirstTileSelected = false;
            liftPlayersFound = false;
            liftConfirmed = false;
            liftSecondTileSelected = false;
            liftFirstTileLocation = -1;
            liftSecondTileLocation = -1;
            playerIndexClicked = -1;
            drawPhaseCompleted = false;
        }

        private void btnResetTurn_Click(object sender, EventArgs e)
        {
            DialogResult dr = new DialogResult();
            dr = MessageBox.Show("Are you sure you want to reset your turn?  This action cannot be undone!", 
                "Reset Turn Confirmation", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                restoreGameState();
            }
        }

        private void saveGameState()
        {
            tempGameTiles = gameTiles;
            tempGameAdvDeck = gameAdvDeck;
            tempGameAdvDiscard = gameAdvDiscard;
            tempTilePanelList = tilePanelList;
            tempPlaceCardDeck = placeCardDeck;
            tempPlaceCardDiscard = placeCardDiscard;
            tempPlayerOneHandList = playerOneHandList;
            tempPlayerTwoHandList = playerTwoHandList;
            tempPlayerThreeHandList = playerThreeHandList;
            tempPlayerFourHandList = playerFourHandList;
            tempPlayerHandList = playerHandList;
            tempNewGame = newGame;
            tempChaliceClaimed = chaliceClaimed;
            tempStatueClaimed = statueClaimed;
            tempTotemClaimed = totemClaimed;
            tempCarvingClaimed = carvingClaimed;
            tempCurrentWaterLevel = currentWaterLevel;
            placeCardDiscardText = lblPlaceCardDiscardName.Text;
            placeCardDiscardForeColor = lblPlaceCardDiscardName.ForeColor;
            placeCardDiscardBackColor = lblPlaceCardDiscardName.BackColor;
            pbPlacesDiscardBackColor = pbPlacesDiscard.BackColor;
            adventureDeckDiscardText = lblAdventureCardDiscardName.Text;
            adventureDeckDiscardForeColor = lblAdventureCardDiscardName.ForeColor;
            adventureDeckDiscardBackColor = lblAdventureCardDiscardName.BackColor;
            pbAdventureDeckDiscardBackColor = pbAdventureDiscard.BackColor;
        }

        private void restoreGameState()
        {
            gameAdvDeck = tempGameAdvDeck;
            gameAdvDiscard = tempGameAdvDiscard;
            tilePanelList = tempTilePanelList;
            newGame = tempNewGame;
            placeCardDeck = tempPlaceCardDeck;
            placeCardDiscard = tempPlaceCardDiscard;
            playerOneHandList = tempPlayerOneHandList;
            playerTwoHandList = tempPlayerTwoHandList;
            playerThreeHandList = tempPlayerThreeHandList;
            playerFourHandList = tempPlayerFourHandList;
            playerHandList = tempPlayerHandList;
            chaliceClaimed = tempChaliceClaimed;
            statueClaimed = tempStatueClaimed;
            totemClaimed = tempTotemClaimed;
            carvingClaimed = tempCarvingClaimed;
            fillAllTiles();
            if (chaliceClaimed)
            {
                pbClaimedChalice.Visible = true;
                pbUnclaimedChalice.Visible = false;
            }
            else
            {
                pbClaimedChalice.Visible = false;
                pbUnclaimedChalice.Visible = true;
            }
            if (statueClaimed)
            {
                pbClaimedStatue.Visible = true;
                pbUnclaimedStatue.Visible = false;
            }
            else
            {
                pbClaimedStatue.Visible = false;
                pbUnclaimedStatue.Visible = true;
            }
            if (totemClaimed)
            {
                pbClaimedDragon.Visible = true;
                pbUnclaimedDragon.Visible = false;
            }
            else
            {
                pbClaimedDragon.Visible = false;
                pbUnclaimedDragon.Visible = true;
            }
            if (carvingClaimed)
            {
                pbClaimedSphinx.Visible = true;
                pbUnclaimedSphinx.Visible = false;
            }
            else
            {
                pbClaimedSphinx.Visible = false;
                pbUnclaimedSphinx.Visible = true;
            }
            setWaterLevel(tempCurrentWaterLevel);
            lblPlaceCardDiscardName.Text = placeCardDiscardText;
            lblPlaceCardDiscardName.ForeColor = placeCardDiscardForeColor;
            lblPlaceCardDiscardName.BackColor = placeCardDiscardBackColor;
            pbPlacesDiscard.BackColor = pbPlacesDiscardBackColor;

            lblAdventureCardDiscardName.Text = adventureDeckDiscardText;
            lblAdventureCardDiscardName.ForeColor = adventureDeckDiscardForeColor;
            lblAdventureCardDiscardName.BackColor = adventureDeckDiscardBackColor;
            pbAdventureDiscard.BackColor = pbAdventureDeckDiscardBackColor;

            updatePlayerHands();
            setDeckLabels();

            pilotSpecialUsed = false;
            if (currentPlayer == 4)
                radSpecial.Enabled = false;
            else
                radSpecial.Enabled = true;
            btnActionSubmit.Enabled = true;
            btnCancel.Enabled = false;
            btnResetTurn.Enabled = false;
            remainingMoves = 3;
            lblActionsRemaining.Text = remainingMoves.ToString();
            rtbGameHistory.AppendText("Turn reset successfully.\n");
            rtbGameHistory.ScrollToCaret();
            clearAllPlayerMarkers();
            //refreshPlayerTokens();
            lblBannerText.Text = "Turn reset.";
        }

        private void checkResetTurn()
        {
            //if (remainingMoves <= 2)
            //    btnResetTurn.Enabled = true;
            //else
                btnResetTurn.Enabled = false;
        }

        private void startNewGamePlayerReset()
        {
            lblPlayerOne.BackColor = Color.Goldenrod;
            lblPlayerOneName.BackColor = Color.Goldenrod;
            lblPlayerOneSpecial.BackColor = Color.Goldenrod;
            pnlPlayerOne.BackColor = Color.Goldenrod;
            lblPlayerTwo.BackColor = Color.DarkGray;
            lblPlayerTwoName.BackColor = Color.DarkGray;
            lblPlayerTwoSpecial.BackColor = Color.DarkGray;
            pnlPlayerTwo.BackColor = Color.DarkGray;
            lblPlayerThree.BackColor = Color.DarkGray;
            lblPlayerThreeName.BackColor = Color.DarkGray;
            lblPlayerThreeSpecial.BackColor = Color.DarkGray;
            pnlPlayerThree.BackColor = Color.DarkGray;
            lblPlayerFour.BackColor = Color.DarkGray;
            lblPlayerFourName.BackColor = Color.DarkGray;
            lblPlayerFourSpecial.BackColor = Color.DarkGray;
            pnlPlayerFour.BackColor = Color.DarkGray;
            currentPlayer = 0;
            radSpecial.Enabled = true;
        }
    }
}
